1 / 6

How to Create And Execute JAR File in Linux

Java developers need to often create & execute JAR File in Linux. Here are the steps to run JAR file in Linux.<br>#java #linux #ubuntu <br><br>Visit https://fedingo.com/how-to-create-execute-jar-file-in-linux/

Download Presentation

How to Create And Execute JAR File in Linux

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. How to Create & Execute Jar File in Linux

  2. Create .java class First we will create a simple Java class with main method for a demo app called HelloWorld. Create an empty .java file using a text editor. $ vim HelloWorld.java Add the following lines to it. It simply prints ‘Hello World’ upon execution. public class HelloWorld { public static void main(String[] args){ System.out.println("Hello World"); } }

  3. Compile & Pack the Class into JAR file Next you need to compile & pack the class into JAR file using javac & jar commands. Basically we first create a class out of our .java code, using javac command. Then we package the class into a .jar file using jar command. $ javac -d . HelloWorld.java $ ls $ jar cvf helloworld.jar HelloWorld.class $ ls

  4. Create Manifest File You need to create a separate manifest file, and update the JAR file to include it, in order to execute the JAR file. Create an empty manifest file. $ vim MANIFEST.MF Copy and paste the following code in it. Main-Class: HelloWorld Save and close the file. Next add the manifest file to the JAR file using the following command. $ jar cvmf MANIFEST.MF helloworld.jar HelloWorld.class

  5. Execute JAR Once the .jar file is created you can execute it with the following command. $ java -jar helloworld.jar Hello World Running the above code produces the desired result. It is important to remember to create a manifest file and add it to the JAR file otherwise you will get the following error. no main manifest attribute, in helloworld.jar Whenever you run a JAR file the Java Virtual Machine (JVM) looks for its manifest attribute to locate the main class containing main method. So the JAR file must contain a line of the form Main-Class:classname to point to the class with main method, that serves as every application’s starting point.

  6. Thank You Visit for details https://fedingo.com/how-to-create-execute-jar-file-in-linux/

More Related