To execute a jar file, you can use the java
command's -jar
myjar.jar
. Because the file is runnable, you can execute it like this: java -jar myjar.jar
Alternatively, the Java Runtime Environment (JRE), when installed on an OS like Microsoft Windows, associates jar files with the JVM so you can double-click on them to run the application. These JARs must be runnable.
The question is: How do you make a JAR runnable?
The manifest file and the Main-Class entry
Inside most JARs, a file called MANIFEST.MF
is stored in a directory called META-INF
. Inside that file, a special entry called Main-Class
tells the java -jar
The problem is that you must properly add this special entry to the manifest file yourself—it must go in a certain place and must have a certain format. However, some of us don't like editing configuration files.
Let the API do it for you
Since Java 1.2, a package called java.util.jar
has let you work with jar files. (Note: It builds on the java.util.zip
package.) Specifically, the jar package lets you easily manipulate that special manifest file via the Manifest
class.
For more details, refer to the link:
http://www.javaworld.com/javaworld/javatips/jw-javatip127.html
No comments:
Post a Comment