Make Executable JAR File
If you have written java program and want to make executable jar file out of it. I will show you how to create executable jar using Eclipse and using command prompt.
Using Eclipse: Create java project in eclipse below is sample where we will create class “ExecutableJar.java” which will be our main entry point through executable jar file:
- ExecutableJar.java:
package com.javahonk; public class ExecutableJar { public static void main(String[] args) { System.out.println("Java Honk executable Jar test successful"); } }
- To create executable jar: Right click project –> Export –> Java –> Runnable JAR File –> Next:
- Choose ExecutableJar.java to launch configuration and export destination then click finish:
- Now you will see Executable.jar got created. To test go to command prompt and use command: “java -jar jarFileName”
- Create JAR from command prompt: Create Manifest.mf file put inside src/main/java folder and include below:
Manifest-Version: 1.0 Main-Class: com.javahonk.ExecutableJar
- Go to command prompt go to the folder you have kept all class file and mainifest file (Note: Manifest.mf file should be in same folder) and execute below command:
“jar cfm Executable.jar Manifest.mf *.class”
- For more information please visit oracle documentation here