Apr 26, 2012

How to invoke a Java application from JAR file

Running JAR Files as Applications


If there is a JAR file which you want to run as a Java application then there is an option to do so by using java command line tool.

java -jar jar-file

The -jar flag tells the interpreter that the application is packaged in the JAR file format. For running the above command, one has to make sure that a class with main method exists and the same has been specified in the META-INF/manifest.mf file present in the JAR file.




One can specify the mail class name in the manifest.mf file as shown below:

Main-Class:


If the manifest entry doesn't exist then the application can not be run from the JAR file. Some important points about calling a Java application from command line tool are:

1) We can not specify more than one jar files with "java -jar command"

2) The presence of manifest.mf file and a correct entry for the main class name is necessary to be present inside the JAR file.

3) All other options like assertions, heap space can be appended while executing the java application from jar file.

No comments:

Post a Comment