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

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.

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.

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.
New release of x64 version, can create 64 bits executives. (May 18,
2008)
Both wizard mode and command line mode supported. (May 18, 2008)
Download: http://www.brothersoft.com/jartoexe-75019.html
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.

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

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.

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.

For Windows, you can convert jar to exe using following ways:
Using Netbeans
https://erainnovator.com/convert-jar-to-exe-file/
Using Excelsior JET
https://youtu.be/iQSfUb8chjg

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

Related

How do I make a code that will make Java code/file to an .exe file [duplicate]

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.
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.
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.
New release of x64 version, can create 64 bits executives. (May 18,
2008)
Both wizard mode and command line mode supported. (May 18, 2008)
Download: http://www.brothersoft.com/jartoexe-75019.html
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.
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
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.
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.
For Windows, you can convert jar to exe using following ways:
Using Netbeans
https://erainnovator.com/convert-jar-to-exe-file/
Using Excelsior JET
https://youtu.be/iQSfUb8chjg
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

error in the execution of treetagger command tag-eng

i 'm trying to do an application in java that use the treetagger.
so tapped this on eclipse
String commande="cmd /c C:\Program Files (x86)\tree-tagger-windows-3.2\TreeTagger\bin\\tag-english"+" "+path;
Process p=Runtime.getRuntime().exec(commande);
But it dosesn't work.
I have not much idea about the TreeTagger and to test if I install TreeTagger under windows I typed these commands on the command prompt cd C: \ Program Files (x86) \ tree-tagger-windows-3.2 \ TreeTagger \ bin and then
tag-English nom_de_fichier_à_tagger but the cmd displays this error message 'perl' is not recognized as an internal or external command, executable program or batch file.
the TreeTagger I install is a zip file I extracted to a folder and I put it in C: \ Program Files (x86) is what I did exactly
if I made a mistake during installation can you help me because I too searched the web and I understood nothing.
It sounds like you need to install a perl on windows. I suggest that you use Strawberry Perl.
I have no experience with TreeTagger, but doing a little googling points to this reference: TreeTagger - a language independent part-of-speech tagger. Scrolling down there is a Windows version in zip form, that contains an INSTALL.txt which states:
Installation
------------
1. Install a Perl interpreter (if you have not already installed one).
You can download a Perl interpreter for Windows for free at
http://www.activestate.com/activeperl/
2. Move the TreeTagger directory to the root directory of drive C:.
3. Download the PC parameter files for the languages you need, decompress
them (e.g. using Winzip or 7zip) and move them to the subdirectory lib.
Rename the parameter files to <language>.par
Example: Rename french-par-linux-3.1.bin to french.par
The UTF8 versions of the parameter files are not supported yet, but
see below some hints on how to build tagging scripts for the UTF8
parameter files.
4. Add the path C:\TreeTagger\bin to the PATH environment variable.
5. Open a shell and type the command
set PATH=C:\TreeTagger\bin;%PATH%
6. Change to the directory C:\TreeTagger
7. Now you can test the tagger, e.g. by analyzing this file with the command
tag-english INSTALL.txt
Obviously you must've skipped step 1. :) You could use ActiveState as they suggest, but these days Strawberry perl is a much better option in my opinion.

Can you run a Java program in Linux using the name only, without the "java" command?

If I am writing HelloWorld, is there a way I can run the program from any directory by just typing HelloWorld? Sort of the same way once you set up Ant, you can just run Ant from any directory?
Just for some details, we are creating a CLI based toolkit for a customer, and just curious if we can compile it, install it, and just have them run it using the toolkit name.
You can always create a shell script, call it HelloWorld and make it run java with your JAR.
You'll then need to chmod the script to make it executable, and place it somewhere in your $PATH.
The script would like something like:
#!/bin/bash
cd /path/to/helloworld
java -jar HelloWorld.jar "$#"
or
#!/bin/bash
java -jar /path/to/helloworld/HelloWorld.jar "$#"
depending on your exact requirements.
Common solution for your problem is to create a separate launcher application, which is non-java application that runs your Java program. Launcher can be written in some compilable language such as C/C++ and compiled into native executable. Also it can be written in some interpreted language such as Unix shell, perl, python etc and made executable by adding #!/path/to/interpreter line at the beginning of launcher file and setting executable flag on it. Also there are several utilities that can generate launcher for your program such as launch4j or jsmooth.
On Linux (specifically), you could use the /proc filesystem (see proc(5) man page) and its binfmt_misc (actually the /proc/sys/fs/binfmt_misc/register pseudo-file and other pseudofiles under /proc/sys/fs/binfmt_misc/) to register java as the handler for .class or .jar files. Read the Documentation/binfmt_misc.txt file in the kernel source for gory details.
Then any executable .jar file would be interpreted by java (or jexec)
I'm not sure it is worth the effort. I find that wrapping your Java program in some shell script is much more easy (and more portable, because few Linux systems actually use binfmt_misc, and your customer may need some sysadmin skills to enable it).

System Startup Folders/Methods on UNIX Platforms?

I have a Java application that needs to implement installation features of making a JAR launch on startup.
I can do this on Window by entering a REG file into the registry, but how can I do this on UNIX platforms? Linux and Mac if the methods are different.
Do Linux and Mac have system startup folders?
Remember that I need to do this programmatically not through system preferences or anything like that.
On Linux, the classic way would be through adding a script in the appropriate /etc/rcN.d/ directory (where N is a number 0-6 representing the 'run level'). I'm not sure whether that's still the recommended way, but it usually is still supported. This would also work with minor variations for other mainstream Unix variants (Solaris, HP-UX, AIX).
On Mac, you have to work harder. The files /etc/rc.common, /etc/rc.imaging and /etc/rc.netboot are related, but there are no /etc/rcN.d directories. There's also a script rc and another rc.local. Typing man rc reveals:
DESCRIPTION
rc.local is now unsupported and has been replaced with launchd(8), which bootstraps itself via the launchctl(1) bootstrap subcommand to read in launchd(8) jobs from the standard locations.
SEE ALSO
launchd(8), launchctl(1)
So, you should investigate launchctl and launchd, particularly launchctl.
This is how I would do it on ubuntu.
First create a bash script to run the java app, similar to.
#!/bin/bash
java -jar "helloworld.jar"
and save it, in this case called 'HELLOWORLD' in /etc/init.d.
Need to make the script executable so need to run
chmod +x HELLOWORLD
Finally to make it run on start up
update-rc.d HELLOWORLD defaults
On Macs I think its launchd, and on linux its init.d. They are config files.

Deploying a Java project on Linux system

I developed a project using Java and now I've to deliver it to client who is using Linux. Which executable file format will be delivered and how to make that?
Executable file format?
If you're delivering a Java app, give them a jar file (and associated libs).
Provide a shell script to set up its environment and execute it.
For example, assuming I define ROOT_DIR as my app's install directory, and so on:
CLASSPATH="${ADD_JARS}:${CLASSPATH}:${ROOT_DIR}/lib/myApp.jar:\
${ROOT_DIR}/lib/jibx/jibx-run.jar:\
${ROOT_DIR}/lib/jibx/xpp3.jar:\
${ROOT_DIR}/lib/bindings.jar:\
${ROOT_DIR}/lib/commons-lang-2.0.jar:\
${ROOT_DIR}/lib/forms-1.0.5.jar"
"${JAVACMD}" -Xmx256M -DanyDefsNeeded=foobar -Dbase.dir="${ROOT_DIR}" -cp "${CLASSPATH}" myApp.main.Launcher "$#"
What goes into the shell script depends totally on what your app actually needs to start up.
A jar. If it is not executable, then a script (.sh) to launch the jar.
Well basically what you wanna put in a .sh file is the commands you'd normally type at the console to run your jar file. They should be separated by a new line (i.e. each on a separate line in the .sh file).
The most basic you can go is add something like this to your sh file:
java -Xms=64m -Xmx=256m -jar myJar.jar -classpath [dependencies dir]/dep1.jar,[dependencies dir]/dep2.jar
beyond this you can do more exotic stuff, like parametrise some environment variables, get command line argumens from when the .sh is launched and pass them to the jar executatble etc. Look up "bash scripting" for advanced stuff:
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-2.html#ss2.1
You might have better luck using Launch4J, IzPack or other installer that has cross-platform capabilities. This might be a better first option than trying to understand the intricacies and idiosyncrasies of the different Linux distributions and shells.
If your app. has a GUI, the best user experience for installation/deployment can be had by way of Java Web Start. Note that JWS can deploy apps. to Windows, *nix and Mac. and avoids all the maintenance woes of generating 3 separate (platform specific) executables.

Categories