We can create a jar file form java class in simple way.If we have a more than one java class, we can combine all the files in single jar.
The command to create jar
jar cf jar-file input-file(s)
The option indicates
c - Create a JAR file.
f - The output to go to a file rather than to stdout.
jar-file is the name that you want the resulting JAR file to have.
The input-file(s) argument is a space-separated list of one or more files that you want to include in your JAR file.
The created Jar looks like
The META-INF/MANIFEST.MF contains meta info about jar
Manifest-Version: 1.0
Created-By: 1.7.0_80 (Oracle Corporation)
Command to run jar file
java -jar HelloWorld.jar
To run the jar file we need to mention Main class in MANIFEST.MF file
other wise will get error Error: Could not find or load main class
Adding main class in MANIFEST.MF
Main-Class: HelloWorld
Important no space between Main-Class and :
The command to create jar
jar cf jar-file input-file(s)
The option indicates
c - Create a JAR file.
f - The output to go to a file rather than to stdout.
jar-file is the name that you want the resulting JAR file to have.
The input-file(s) argument is a space-separated list of one or more files that you want to include in your JAR file.
The created Jar looks like
The META-INF/MANIFEST.MF contains meta info about jar
Manifest-Version: 1.0
Created-By: 1.7.0_80 (Oracle Corporation)
Command to run jar file
java -jar HelloWorld.jar
To run the jar file we need to mention Main class in MANIFEST.MF file
other wise will get error Error: Could not find or load main class
Adding main class in MANIFEST.MF
Main-Class: HelloWorld
Important no space between Main-Class and :
No comments:
Post a Comment