You can make a
.jar file executable. What this means is that all
you have to do to run your program is to double-click on the
Please do this for all future submissions; it's much easier for us to grade.
There are two parts to doing this:
.jarfile with a line in the
MANIFEST.MFfile telling where to find the correct
mainmethod (there can be more than one
.jarfiles. It is a good idea to test your jar file before turning it in to be graded!
The easy way: BlueJ
mainmethod you want the program to start from (remember, any class may have a
mainmethod, so BlueJ doesn't know which one you want).
.jar), and click Create.
The not-too-difficult way: Manually
.classfiles (and anything else you want to include) together in a single directory.
myManifest) containing the following lines:
MyMainClassis the name of the class containing the
mainmethod you want to use.
jar cvfm myResult.jar myManifest *.java *.class
myResult.jaris the jar file you are trying to create,
myManifestis the file you created in step 2, and everything else is the files you want to include.
The hard way: Forté
Executing an executable jar file:
There are two ways to execute the jar file:
java -jar myResult.jar. This should work; if it doesn't, there are two main possibilities:
'java' is not recognized as an internal or external command, operable program or batch filemeans that you don't have your system configured properly to run Java.
Exception in thread "main" java.lang.NoClassDefFoundError: MyMainClassmeans that the jar file was not constructed properly. The most likely error is having something in the wrong directory when you created the jar.
To make jar files executable (Windows 98):
These instructions are for Windows 98. They aren't hard to adapt to Windows 2000; I don't know about the other assorted varieties of Windows.
In Windows file Explorer, choose View -> Folder Options..., then select the File Types tab. Check to see if there is a file type of Executable Jar File:
javaw.exefile and make a note of its location For example, mine is
C:\Program Files\Java\j2re1.4.0\bin\javaw.exe -jar "%1"where the part before
-jaris the path you found in step 1.