How can I convert a .jar to an .exe?

JavaWindowsExe

Java Problem Overview


I want to convert a .jar to an .exe for microsoft. Is there any program converter for this?

Also if there's one for Mac and Linux I would appreciate suggestions for those too.

Java Solutions


Solution 1 - Java

Launch4j works on both Windows and Linux/Mac. But if you're running Linux/Mac, there is a way to embed your jar into a shell script that performs the autolaunch for you, so you have only one runnable file:

exestub.sh:

#!/bin/sh
MYSELF=`which "$0" 2>/dev/null`
[ $? -gt  0 -a -f "$0" ] && MYSELF="./$0"
JAVA_OPT=""
PROG_OPT=""
# Parse options to determine which ones are for Java and which ones are for the Program
while [ $# -gt 0 ] ; do
	case $1 in
		-Xm*) JAVA_OPT="$JAVA_OPT $1" ;;
		-D*)  JAVA_OPT="$JAVA_OPT $1" ;;
		*)    PROG_OPT="$PROG_OPT $1" ;;
	esac
	shift
done
exec java $JAVA_OPT -jar $MYSELF $PROG_OPT

Then you create your runnable file from your jar:

$ cat exestub.sh myrunnablejar.jar > myrunnable
$ chmod +x myrunnable

It works the same way launch4j works: because a jar has a zip format, which header is located at the end of the file. You can have any header you want (either binary executable or, like here, shell script) and run java -jar <myexe>, as <myexe> is a valid zip/jar file.

Solution 2 - Java

JSmooth .exe wrapper

JSmooth is a Java Executable Wrapper. It creates native Windows launchers (standard .exe) for your Java applications. It makes java deployment much smoother and user-friendly, as it is able to find any installed Java VM by itself. When no VM is available, the wrapper can automatically download and install a suitable JVM, or simply display a message or redirect the user to a website.

JSmooth provides a variety of wrappers for your java application, each of them having their own behavior: Choose your flavor!

Download: http://jsmooth.sourceforge.net/

JarToExe 1.8 Jar2Exe is a tool to convert jar files into exe files. Following are the main features as describe on their website:

Can generate “Console”, “Windows GUI”, “Windows Service” three types of .exe files.

Generated .exe files can add program icons and version information. Generated .exe files can encrypt and protect java programs, no temporary files will be generated when the program runs.

Generated .exe files provide system tray icon support. Generated .exe files provide record system event log support. Generated windows service .exe files are able to install/uninstall itself, and support service pause/continue.

Executor

Package your Java application as a jar, and Executor will turn the jar into a Windows .exe file, indistinguishable from a native application. Simply double-clicking the .exe file will invoke the Java Runtime Environment and launch your application.

Solution 3 - Java

If your program is "publicly available non-commercial in nature" and has "a publicly available Web site that meets the basic quality standards", then you can try and get a free license of Excelsior. If its not then it's expensive, but still a viable option.

Program: https://www.excelsiorjet.com

As a side note: Here's a study of all existing Jar to EXE programs, which is a bit depressing - https://www.excelsior-usa.com/articles/java-to-exe.html

Solution 4 - Java

Despite this being against the general SO policy on these matters, this seems to be what the OP genuinely wants:

http://www.google.com/search?btnG=1&pws=0&q=java+executable+wrapper

If you'd like, you could also try creating the appropriate batch or script file containing the single line:

java -jar MyJar.jar

Or in many cases on windows just double clicking the executable jar.

Solution 5 - Java

I used Launch4J and it works flawlessy,

  • First, Go to your jdk and copy the bin and lib folder
  • Then create a folder for your app and make a folder called jre-(version),
  • Then paste these inside
  • Then open launch4j Put the exe file's path (Inside the app's folder)
  • Then go the jre option and inside bundled paths type jre-(version)
  • Then in minimun version type the version of the java you coded it in.
  • Then in the jre option put "Only use private jdk runtimes"
  • Then hit the gear icon. It will open a file chooser.
  • Choose your application's folder, done
  • Now open the exe file generated. It should work.

In case it does not, try the test run button (The green play one). If it says LinkageError in the console below, then in the jvm-options type --enable-preview. It should work. I hope it helped.

Solution 6 - Java

For Windows, you can convert jar to exe using following ways:

  1. Using Netbeans https://erainnovator.com/convert-jar-to-exe-file/
  2. Using Excelsior JET https://youtu.be/iQSfUb8chjg

Solution 7 - Java

if you need to convert from .jar to .exe from java 14 you can used jpackage

> jpackage is a command-line tool to create native installers and > packages for Java applications.

this article will help you

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNegrodamus12View Question on Stackoverflow
Solution 1 - JavaMatthieuView Answer on Stackoverflow
Solution 2 - JavaMonnyView Answer on Stackoverflow
Solution 3 - JavaTheLQView Answer on Stackoverflow
Solution 4 - JavaTim BenderView Answer on Stackoverflow
Solution 5 - JavadeateaterOGView Answer on Stackoverflow
Solution 6 - JavaAshish DholeView Answer on Stackoverflow
Solution 7 - JavaAhmed SaberView Answer on Stackoverflow