Ccna final exam - java, php, javascript, ios, cshap all in one. This is a collaboratively edited question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
I've just made a simple program with eclipse and I want to compile it into an exe file, but can't seem to found out how to do it simply. Any suggestions?
1- 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 web site.
JSmooth provides a variety of wrappers for your java application, each of them having their own behaviour: Choose your flavour!
Download: http://jsmooth.sourceforge.net/
2- JarToExe 1.8 Jar2Exe is a tool to convert jar files into exe files. Following are the main features as describe in 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 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)
3- 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.
Download: http://mpowers.net/executor/
4- Advanced Installer Advanced Installer lets you create Windows MSI installs in minutes. This also has Windows Vista support and also helps to create MSI packages in other languages. Download: http://www.advancedinstaller.com/ Let me know other tools that you have used to convert JAR to EXE.
I would use GCJ (GNU Compiler for Java) in your situation. It's an AOT (ahead of time) compiler for Java, much like GCC is for C. Instead of interpreting code, or generating intermediate java code to be run at a later time by the Java VM, it generates machine code.
GCJ is available on almost any Linux system through its respective package manager (if available). After installation, the GCJ compiler should be added to the path so that it can be invoked through the terminal. If you're using Windows, you can download and install GCJ through Cygwin or MinGW.
I would strongly recommend, however, that you rewrite your source for another language that is meant to be compiled, such as C++. Java is meant to be a portable, interpreted language. Compiling it to machine code is completely against what the language was developed for.
I usually use a bat script for that. Here's what I typically use:
@echo off set d=%~dp0 java -Xmx400m -cp %d%myapp.jar;%d%libs/mylib.jar my.main.Class %*
The %~dp0 extract the directory where the .bat is located. This allows the bat to find the locations of the jars without requiring any special environment variables nor the setting of the PATH variable.
We have found Jsmooth to be well-working and easily scriptable with ant under Linux. You may want to use one-jar (also easily scriptable with ant under Linux) to collect a multifile application in a single jar first.
We primarily needed the easy deployment of the EXE combined with the "hey, you need Java version X, go here to download" facilities.
(but what you most likely need is the "Runnable jar" / "Executable jar" facility in standard Java).
You can convert .jar file to .exe on these ways:
ReplyDelete1- 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 web site.
JSmooth provides a variety of wrappers for your java application, each of them having their own behaviour: Choose your flavour!
Download: http://jsmooth.sourceforge.net/
2- JarToExe 1.8
Jar2Exe is a tool to convert jar files into exe files.
Following are the main features as describe in 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 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
3- 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.
Download: http://mpowers.net/executor/
4- Advanced Installer
Advanced Installer lets you create Windows MSI installs in minutes. This also has Windows Vista support and also helps to create MSI packages in other languages.
Download: http://www.advancedinstaller.com/
Let me know other tools that you have used to convert JAR to EXE.
I would use GCJ (GNU Compiler for Java) in your situation. It's an AOT (ahead of time) compiler for Java, much like GCC is for C. Instead of interpreting code, or generating intermediate java code to be run at a later time by the Java VM, it generates machine code.
ReplyDeleteGCJ is available on almost any Linux system through its respective package manager (if available). After installation, the GCJ compiler should be added to the path so that it can be invoked through the terminal. If you're using Windows, you can download and install GCJ through Cygwin or MinGW.
I would strongly recommend, however, that you rewrite your source for another language that is meant to be compiled, such as C++. Java is meant to be a portable, interpreted language. Compiling it to machine code is completely against what the language was developed for.
I use launch4j
ReplyDeleteANT Command:
<target name="jar" depends="compile, buildDLLs, copy">
<jar basedir="${java.bin.dir}" destfile="${build.dir}/Project.jar" manifest="META-INF/MANIFEST.MF" />
</target>
<target name="exe" depends="jar">
<exec executable="cmd" dir="${launch4j.home}">
<arg line="/c launch4jc.exe ${basedir}/${launch4j.dir}/L4J_ProjectConfig.xml" />
</exec>
</target>
OK, there you can get the detailed analysis of your requirement
ReplyDeletehttp://www.excelsior-usa.com/articles/java-to-exe.html
There is a small handful of programs that do that... TowerJ is one that comes to mind (I'll let you Google for it) but it costs significant money.
ReplyDeleteThe most useful reference for this topic I found is at: http://mindprod.com/jgloss/nativecompiler.html
it mentions a few other products, and alternatives to achieve the same purpose.
I usually use a bat script for that. Here's what I typically use:
ReplyDelete@echo off
set d=%~dp0
java -Xmx400m -cp %d%myapp.jar;%d%libs/mylib.jar my.main.Class %*
The %~dp0 extract the directory where the .bat is located. This allows the bat to find the locations of the jars without requiring any special environment variables nor the setting of the PATH variable.
The thing you can do is create a .bat that will execute the .jar file created, checking if there is a JRE present.
ReplyDeleteFrom Mitch useful link (source)
java -classpath myprogram.jar de.vogella.eclipse.ide.first.MyFirstClass
This can be used into your batch...
We have found Jsmooth to be well-working and easily scriptable with ant under Linux. You may want to use one-jar (also easily scriptable with ant under Linux) to collect a multifile application in a single jar first.
ReplyDeleteWe primarily needed the easy deployment of the EXE combined with the "hey, you need Java version X, go here to download" facilities.
(but what you most likely need is the "Runnable jar" / "Executable jar" facility in standard Java).
There is no exe for Java and It doesn't make sense to create one.
ReplyDeleteYour installation program should provide a shortcut to start the program.
The shortcut can have the command line.
java -classpath myprogram.jar de.vogella.eclipse.ide.first.MyFirstClass
For you, you can also create a batch file but there will be a CLI windows.
@echo off
set d=%~dp0
java -classpath myprogram.jar de.vogella.eclipse.ide.first.MyFirstClass
As you can see, Windows has some lack of coherence but you still can install another Operating System instead.