JARs are Java Archives. They can do much more than only store source your compilations. JARs, WARs and EARs, can hold extra informations to be useful later in the runtime.
JAR can be executable
JAR file can be "executable". Java launcher will automatically know which class to launch when executing the JAR file. You should create an entry into the JAR's manifest file
Now you can execute your code via
JARs can hold dependency informatin
JARs allows a declaration of other JAR dependencies to be in the manifest, which implicitly creates the CLASSPATH without you having to declare it.
The
JARs can be implicitly referenced
If you have several different command-line utilities (or other applications) that make use (e.g) of the Spring framework, you can put the Spring JAR files into a common location. to avoid having multiple copies of JARs. The Java runtime's common location for JARs, known as the "extension directory," is located in the
Java 6 can use classpath wildcards
To avoid huge
JAR can be executable
JAR file can be "executable". Java launcher will automatically know which class to launch when executing the JAR file. You should create an entry into the JAR's manifest file
MANIFEST.MF
in the JAR's META-INF
subdirectory: Main-Class: com.jpoint.Hello
Now you can execute your code via
java -jar app.jar
. In your GUI, double-click the JAR file to do the same.JARs can hold dependency informatin
JARs allows a declaration of other JAR dependencies to be in the manifest, which implicitly creates the CLASSPATH without you having to declare it.
The
Class-Path
attribute contains a relative reference to the JAR files the application depends on. It can be written as an absolute reference or without a prefix entirely, in which case it would be assumed that the JAR files were in the same directory as the application JAR. The value
attribute of the Ant Class-Path
attribute has to appear in one line.JARs can be implicitly referenced
If you have several different command-line utilities (or other applications) that make use (e.g) of the Spring framework, you can put the Spring JAR files into a common location. to avoid having multiple copies of JARs. The Java runtime's common location for JARs, known as the "extension directory," is located in the
lib/ext
subdirectory, underneath the installed JRE locationJava 6 can use classpath wildcards
To avoid huge
CLASSPATH
environment variables or command-line -classpath
parameters, Java 6 introduced the notion of the classpath wildcard. The classpath wildcard lets you specify lib/*
, and all of the JAR files listed in that directory (but not recursively), in the classpath. The classpath wildcard doesn't hold for the previously discussed Class-Path
attribute manifest entry.