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.
I would say launch4j is the best tool for converting a java source code(. java) to .exe file You can even bundle a jre with it for distribution and the exe can even be iconified.
An Exe file is an executable file that can be executed in Microsoft OS environment. Jar file is container of Java Class files, including other resources related to the project. Jar file can be executed only if Java run time environment.
FYI: In simple terms, the difference between a JAR file and a Runnable JAR is that while a JAR file is a Java application which requires a command line to run, a runnable JAR file can be directly executed by double clicking it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With