Step 1: Locate the Jar utility in the JDK folder
- Before you do anything else, make sure that you have jdk installed on your computer. You also will need to know the directory to the jdk. Specifically, you will need the path to the Jar utility that is inside your jdk folder. My path to jar is:
· C:\"Program Files"\Java\jdk1.6.0_02\bin\jar
- As you can probably tell, I'm using Java 1.6 and within the 'bin' folder is jar which is the program that you will use to make jar files. Basically typing that line up above tells the command prompt that we're going to run the jar utility which is located in the folder C:\"Program Files"\Java\jdk1.6.0_02\bin
- On your own computer, the path to the jar utility will probably look similar, it depends on where you installed the jdk to.
Step 2: Create themanifest file
Since you could potentially be compiling many files into one jar file, Java needs to know which one will have the main method. Our example is a bit more trivial since we're just compiling one class into a Jar. Nonetheless, the way that Java knows which of classes has the main method is from a single line in what's known as a manifest file. A manifest file can be a text file made with notepad. I called my manifest file manifest.txt, my manifest file says:
Main-Class: JarDemo
Use the command prompt to navigate to where the JarDemo.class and manifest.txt file are saved and type :
C:\> C:\Path\to\jdk\bin\jar cvfm jarDemoCompiled.jar manifest.txt JarDemo.class
If you don't like always typing out the generally long path to the jdk. You can set the path as follows
c:> path c:\path\to\jdk\bin;%path%
Doing so would allow you to type
C:\> jar cvfm jarDemoCompiled.jar manifest.txt JarDemo.class
When I don't usde the shortcut on my computer, I must type:
C:\> C:\"Program Files"\Java\jdk1.6.0_02\bin\jar cvfm jarDemoCompiled.jar manifest.txt JarDemo.class
cvfm means "create a jar; show verbose output; specify the output jar file name (jarDemoCompiled.jar); specify the manifest file name(manifest.txt) and use the file JarDemo.class to create the jar
If you don't like always typing out the generally long path to the jdk. You can set the path as follows
c:> path c:\path\to\jdk\bin;%path%
Doing so would allow you to type
C:\> jar cvfm jarDemoCompiled.jar manifest.txt JarDemo.class
When I don't usde the shortcut on my computer, I must type:
C:\> C:\"Program Files"\Java\jdk1.6.0_02\bin\jar cvfm jarDemoCompiled.jar manifest.txt JarDemo.class
cvfm means "create a jar; show verbose output; specify the output jar file name (jarDemoCompiled.jar); specify the manifest file name(manifest.txt) and use the file JarDemo.class to create the jar

About
Tags
Popular


0 comments:
Post a Comment