Java ARchive (JAR) Files 101, Page 2
JAR File in App Deployment
Now that you have a JAR file, you may want to use it as part of your application deployment process. Typically, you will form many JARs for different application components (client and server, for instance) and use them in an application.The class MyApplication.java, which is bundled in the JAR file, is only an example. For actual deployments, you would bundle only the .class files instead of the .java files. Assuming that you have now bundled the MyApplication.class file, you can execute this class file. The java command has an option for this.
The command java jar MyApplication.jar would result in the following output:
Failed to load Main-Class manifest attribute from MyApplication.jar
Main-Class: com.mycomp.demo.MyApplication
Now the modified MANIFEST.MF file will have the following contents:
Manifest-Version: 1.0 Created-By: 1.5.0_19 (Sun Microsystems Inc.) Main-Class: com.mycomp.demo.MyApplication
Also, in the Java ARchive_src.zip code download, the MyApplication.java file is updated as follows with the string main method of MyApplication:
package com.mycomp.demo;
public class MyApplication
{
public static void main(String args[])
{
System.out.println("main method of MyApplication.");
}
}
The addition of the main class is also referred to as defining the entry point for the JAR file.
To update your MyApplication.jar file, repackage the class file and the updated MANIFEST.MF file. Now, execute the command java jar MyApplication.jar to get the desired result.
Page 2 of 3
