"jar -ufe" Command to Create an Executable JAR

Q

What is the "jar" command to create an executable JAR? I know the starting class name in the JAR file.

✍: FYIcenter.com

A

If you know the starting class name and that class is in the JAR file, you can use the "jar -uvfe jarname classname" to make JAR file as executable.

For example, I want to make myNew.jar executable with the Hello class:

\fyicenterjar>"%java_home%\bin\jar" -uvfe myNew.jar Hello
updated manifest

\fyicenter>"%java_home%\bin\java" -jar myNew.jar
Hello new world!

\fyicenter>"%java_home%\bin\jar" -xvf myNew.jar

\fyicenter>type META-INF\MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.8.0_45 (Oracle Corporation)
Main-Class: Hello

As you can see from the output, "jar -uvfe myNew.jar Hello" command just added "Main-Class: Hello" to the MANIFEST.MF file. Of course, you can manually, edit the MANIFEST.MF file and put it in the JAR file.

Back to FAQ for JDK JAR (Java ARchive) Tool.

2016-06-13, 1270👍, 0💬