Computer Science Canada

Creating Executable JAR file (from java class file)

Author:  MR-D [ Thu Dec 02, 2004 8:45 pm ]
Post subject:  Creating Executable JAR file (from java class file)

Hi all:

Just wondering the easiest way to create an executable JAR file from a java class file. One that can be double-clicked in windows and launch the application.

I usually just write up a batch file, but this won't work due to network restrictions.

Also, the dos "jar" command-line command doesn't seem to be working (jar isn't recognized as a command).

THanks,
MRD

Author:  MysticVegeta [ Fri May 06, 2005 5:48 pm ]
Post subject: 

I dont think you can launch it directly by windows. Only from the command prompt i think ->
after locating the directory
java -jar filename.jar

Author:  rizzix [ Fri May 06, 2005 10:16 pm ]
Post subject: 

no you can launch it directly from windows.. just double click it.. btw.. the command is something like this:

code:
cd to_compiled_class's_base_directory
jar -cfm myjar.jar . manifest_file


just make sure in ur manifest file (an empty plain text file) you add lines similar to the following:
code:
Main-Class: mypackage.my_main_class_file
where the my_main_class_file is the .class file containing the public static void main(String[]); method

Author:  jskopek [ Wed May 18, 2005 11:54 am ]
Post subject: 

just out of curiosity... how would you do this if you need to import drivers? for example, whenever I run my database-communicating application, I need to type
java -classpath sqlconn.jar:. LinkBrowser
is it possible to turn that into a jar file?

Author:  rizzix [ Wed May 18, 2005 2:16 pm ]
Post subject: 

extract the contents of that driver jar and add those contents to your jar (just exclude the META dir)

Author:  jskopek [ Wed May 18, 2005 11:19 pm ]
Post subject: 

huh? so you create your jar fist using the command lines shown above, then you extract the external jar file into your file?

Author:  rizzix [ Thu May 19, 2005 7:46 am ]
Post subject: 

no first extract and then jar them all together.

Author:  1of42 [ Thu Jun 02, 2005 9:42 pm ]
Post subject: 

OK, I found this thread very useful. One thing though:

If I create an executable jar, it works perfectly in cmd (ie using the java -jar command). However, when I click on it thru the normal Explorer widnows, it will not in fact do the terminal stuff I need it to do(use standard input to ask a couple of things). Anybody know the reason?


: