Solved

2007 How to: COMPILE \ RUN java programs (code) in Windows (XP...) as a standalone app? BEST WAY

Posted on 2007-03-20
18
386 Views
Last Modified: 2010-03-31
2007 How to: COMPILE \ RUN java programs (code) in Windows (XP...) as a standalone app? BEST WAY

I have found numerous postings for this question but most are outdated, poorly answered or incomplete. So maybe this could be definitive...

COMPILING \ RUNNING java programs (code) in Windows (XP...)

I am unclear on how to "BEST" take my java program (.java) or create a (.class or .jar) and then send this to my friends and family who have Windows XP and have them be able to execute the program as a standalone app.

Many posts say I should just be able to double-click the .jar or .class file but this doesn't seem to work for many people. Some posts just offer links to apps that can create an .exe file (fine with me but they seem testy and flaky unless someone uses "a really good one.").

Some posts even want me to open a dos prompt and type java -cp .. whatever, no way!

So what is the BEST way to make my code portable as an executable (i.e. "Hey Jim! Just download this game I wrote in java into any folder and just double-click, it is so cool!"

Any help clearing up this "mysterious, why?" issue would be GREATLY appreciated!


Karl66
0
Comment
Question by:Karl66
  • 7
  • 6
  • 5
18 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 18759504
You can use Java Web Start. That will install a JRE if it's missing. jars are only going to work under special circumstances
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 18759508
0
 

Author Comment

by:Karl66
ID: 18759567
Java Web Start software provides a flexible and robust deployment solution for Java technology-based applications based on the Java Community Process program (JCP).?

CEHJ are you saying that "Java Web Start" will compile my .class file to an .exe? If not how exactly will this help me make my apps standalone and portable and is this the BEST way to do this?

Thanks in adavance!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18759839
No. JWS works by serving your app from a web server, packaged and deployed in such a way that the correct runtime is installed. exe files are platform-specific, which somewhat defeats the object of Java
0
 

Author Comment

by:Karl66
ID: 18760023
OK. Anyone have thoughts if I wanted to make the app Windows platform specific? A decent compiler? Jet exe4j or something else. It is possible I am being dense here but it seems that my whizzy java gui apps I have written should be able to launch for people as standalone apps on my windows box.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18760071
Dependency free Java (i.e. a runtime) is really a kind of contradiction in terms. If that's what you want, you're really working in the wrong language if you need to produce executables. Java is an interpreted lanaguage and therefore needs an interpreter. Using JWS will ensure that dependencies are resolved in as painless a way as possible
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 18760109
You can always look at JARing your classes together to ensure smooth portability across platforms:

http://java.sun.com/docs/books/tutorial/deployment/jar/

You also get the advantages of signing, security, manifest, etc
0
 

Author Comment

by:Karl66
ID: 18760793
CEHJ - thanks.

I am moving from the C world and like java. I have written some code I like and want to make it available. I ask the following then to make sure I am clear:

You do not like the compilers I hear so much about such as jet?
There is no way through Netbeans 5.5 I can create a file I can email and have person2 execute?
Using a JWS solution is the way most people make their "stuff" available?
Am I on-track?

Thanks again.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 18760839
>> There is no way through Netbeans 5.5 I can create a file I can email and have person2 execute?

You can create an executable JAR file and send it, assuming the other person has the same version of Java available to run it
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Karl66
ID: 18761121
mayankeagle -

Are you saying they can double-click - would they need the same runtime or JDE as in exactly the same version? What is really really really the best way to send someone a java app and say run this have a nice day. I cannot believe it is such a rabbit hole but I guess it is.

Thanks
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 18761531
They can double click on it and run if it they have a JRE (preferably same version or higher than yours) and if their default opener for .jar files is java.exe or javaw.exe
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18762459
>>You do not like the compilers I hear so much about such as jet?

Not really, as there's not much point in writing in an interpreted language if one's intention is to produce a native executable. All things like Jet do is to bundle an interpreter with your code and wrap it in an exe.

If you're really keen on Java -> native code, you'd be better to use gcj with Cygwin (assuming Windows) then you'll get genuine native code
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 18768881
>> code portable as an executable

If it is executable (as an EXE) it might not be portable to all platforms - what exactly do you want? A standard thing to port to all platforms, or multiple platform-specific native executables?
0
 

Author Comment

by:Karl66
ID: 18768923
Good question. Here is what happened...

Work wanted a GUI front end that would query an excel (ODBC) spreadsheet and give results based on the GUI inputs. I ws taking java in college - wrote it. It works. I like it. I googled how do I make my java program portable to my windows clients. I got silence.... as if I was asking how to make gold from water. So all I really need now is a good way to make a windows exe - I would love to try CEHJ's web delivery thought (if a simple implimentation) or his exe creator gcj (for which I am still searchng a working download link [CEHJ have one?]) but for now I want to zip up a sheet and an exe and say "have a nice day"

Thanks guys
Karl
0
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 125 total points
ID: 18768938
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18769711
If you want gcj, it's part of gcc, both of which will require Cygwin (or MinGW) to be installed first if you're on Windows:

http://sourceware.org/cygwin/

http://www.mingw.org/
0
 

Author Comment

by:Karl66
ID: 18836188
RESOLVED:

I had all clients simply update to the the latest JRE, I used exe4j (free trial) to make a Windows exe. Zipped everything up (the database and the exe and the JRE 6 download) and it works. I will accept multiple answers as CEHJ is right but I needed mayankeagles blance of OK if you must...

thanks all
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18836217
:-)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now