
-----------------------------------
MR-D
Thu Dec 02, 2004 8:45 pm

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

-----------------------------------
MysticVegeta
Fri May 06, 2005 5:48 pm


-----------------------------------
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

-----------------------------------
rizzix
Fri May 06, 2005 10:16 pm


-----------------------------------
no you can launch it directly from windows.. just double click it.. btw.. the command is something like this:

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: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

-----------------------------------
jskopek
Wed May 18, 2005 11:54 am


-----------------------------------
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?

-----------------------------------
rizzix
Wed May 18, 2005 2:16 pm


-----------------------------------
extract the contents of that driver jar and add those contents to your jar (just exclude the META dir)

-----------------------------------
jskopek
Wed May 18, 2005 11:19 pm


-----------------------------------
huh? so you create your jar fist using the command lines shown above, then you extract the external jar file into your file?

-----------------------------------
rizzix
Thu May 19, 2005 7:46 am


-----------------------------------
no first extract and then jar them all together.

-----------------------------------
1of42
Thu Jun 02, 2005 9:42 pm


-----------------------------------
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?
