aspose file tools*
The moose likes Beginning Java and the fly likes Executable java file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Executable java file" Watch "Executable java file" New topic
Author

Executable java file

Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello,
Could you please tell me how to create an executable file for a java appliction.
step by step instruction are much appriciated.
thanks


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Paul Zill
Greenhorn

Joined: Jun 12, 2003
Posts: 28
can you be a bit more specific?
if you just want to run a java app instead of typing it from the command line just create a shortcut and for target put in "<path to java>java <path to class file>TestApplication"
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Heloo,
I mean if I want to give this the program to a person who doesn't know java. I should give him with an executable file. so that he can double click the icon and get the program to run
hope this is more specific
Paul Zill
Greenhorn

Joined: Jun 12, 2003
Posts: 28
well then . . .
in windows you can create a batch file (.bat) which does the same thing as the shortcut.
The only problem would be is if the person has java installed and their environment variables set (like a JAVA_HOME, or the jdks' bin\ directory in the path).
You could circumvent this by also including the jdk with your application (it's about 46 mb for 1.4) and calling that one explicitly in your batch file.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Another possibility (more common) is the executable .jar file. An executable .jar file is simply a .jar file with an extra line in the manifest:
Main-Class: my.main.ClassName
When you double click on this .jar file, the applciation should launch(*)
However, an executable .jar file IGNORES the system CLASSPATH variable. You can specify a Class path in the manifest:
Class-Path: anotherJarFile.jar ..
Note the capitalization and hyphenation of "Class-Path" Also note that the elements listed are relative to the location of the .jar file and not relative to the current directory or anything else. Also note that the different elements are separated by spaces, not : or ;
---------------
(*) This is, of course, assuming that the JRE is correctly installed. Just include the distribution .exe with the application, and tell the client that if they don't have java already installed on the target machine, they will have to install it before running their program. I usually have the client open up a DOS prompt (or the equivelent) and type java -version. This double checks that java is installed and enables you/the user to verify that the required version is installed. There are ways to automate this for "dumb" users, but I gave my mother these instructions and she could follow them....
One other note--an executable jar file is defaulted to run with the javaw command, not the java command. This means that you won't get a DOS prompt/whatever upon double clicking, and any System.out.prinln() messages (or the equivelent) will not show up.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Thanks for the answers....
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
http://www.coderanch.com/t/391746/java/java/Game-Tutorials-Creating-Executable-JAR


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
jQuery in Action, 2nd edition
 
subject: Executable java file