Java Reference
In-Depth Information
jar -cv -m manifest.stub -f /tmp/com.darwinsys.util.jar .
The jar program and related tools add additional information to the manifest, including a list-
ing of all the other files included in the archive.
TIP
If youuse a tool like Maven (see Automating Dependencies, Compilation, Testing, and
Deployment with Apache Maven ) , it will automatically create a JAR file from your
source project just by saying mvn package .
Running a Program from a JAR
Problem
You want to distribute a single large file containing all the classes of your application and run
the main program from within the JAR.
Solution
Create a JAR file with a Main-Class : line in the manifest; run the program with the java -
jar option.
Discussion
The java command has a -jar option that tells it to run the main program found within a
JAR file. In this case, it will also find classes it needs to load from within the same JAR file.
How does it know which class to run? You must tell it. Create a one-line entry like this, not-
ing that the attribute fields are case-sensitive and that the colon must be followed by a space :
Main-Class: com.somedomainhere.HelloWorld
Search WWH ::




Custom Search