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 .jar file.
Please do this for all future submissions; it's much easier for us to grade.
There are two parts to doing this:
.jar file with a line in the MANIFEST.MF
file telling where to find the correct main method (there can
be more than one main method). .jar
files. It is a good idea to test your jar file before turning
it in to be graded!The easy way: BlueJ
main method you want the program to start from (remember,
any class may have a main method, so BlueJ doesn't know which
one you want)..jar), and click Create.The not-too-difficult way: Manually
.java files and .class
files (and anything else you want to include) together in a single directory.myManifest)
containing the following lines: Manifest-Version: 1.0
Main-Class: MyMainClass
where MyMainClass is the name of the class
containing the main method you want to use. jar cvfm myResult.jar myManifest
*.java *.classmyResult.jar is the jar file you are trying to create,
myManifest is 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 file means that you don't have your system configured
properly to run Java.Exception in thread "main" java.lang.NoClassDefFoundError: MyMainClass
means 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.exe file and make a note of its location For
example, mine is C:\Program Files\Java\j2re1.4.0\bin\javaw.exe.
C:\Program Files\Java\j2re1.4.0\bin\javaw.exe
-jar "%1"
where the part before -jar is the path you found in step
1.