What is a JAR file in Java and how to create one?
A JAR (Java ARchive) file is a ZIP file which holds compiled .class files, resources and a manifest. It is the normal way to share a Java library or an application.
public class Hello {
public static void main(String[] args) {
System.out.println("Running from a JAR");
}
}
Terminal
$ javac Hello.java
$ jar cfe app.jar Hello Hello.class
$ java -jar app.jar
Running from a JAR
$ jar tf app.jar
META-INF/
META-INF/MANIFEST.MF
Hello.class
ccreate,ffile name,eentry point (the class withmain).jar tflists the content of a JAR.
Real projects use Maven or Gradle to build the JAR.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |