Convert jar to exe - java

I try to convert a jar file to an exe file.
I followed the instructions provided here using launch4j .
I get only an XML file but no exe as expected.
Any ideas?

So how should I deploy my application?
Your user would have to have the JRE installed on their computer. However, you could also distribute java.exe and rt.jar (the java run time jar) as well as any library jars you need for your application along with your program. Since the java command has an optional classpath parameter you could write a batch file (something like runme.bat) which would look something like this:
java -cp rt.jar;myapplication.jar;otherjars.jar MyMainClass
This is still Windows specific because the java.exe file would be a Windows specific file. You could also add in logic to check for the environment variable JAVA_HOME and if that's set on the user's computer then the java program specific to their OS would be in JAVA_HOME/bin
Your real problem comes when you're not sure what operating system your user will be using AND you don't know if they have Java installed. If you simply require that the user has the Java Runtime Environment installed then you're problem is solved for all users.
I hope that helps.
Greg

Related

How to make a .jar open using a specific jdk?

I've ran into an issue. I'm running on macOS Sierra (10.12.1). This .jar file I downloaded requires a JDK. So, I installed JDK8 (jdk180121). I was able to extract JDK8 .pkg without typing in my password (authenticate). I then tried to place the new folder into the proper place. However, it asks me to authenticate the JDK (aka asks for the password). I do not want to give my password, so, therefore, I can't place it in the proper location. However, I still need to open the .jar file I mentioned earlier. How can I point the .jar file to where the JDK8 is located?
OSX: 10.12.2
JDK: jdk180121
.jar: craftbukkit-1.11.2(.jar)
To launch with a specific JRE (You wouldn't need the JDK to just run an application) you can do it through the command line.
Open a terminal and navigate to the directory with the Java binary and launch this way:
java -jar path/to/jar/program.jar

How to call an embedded jre from command line in order to run java applications

Is it possible to bundle a JRE within an exported stand alone Java app? We have a very specific requirement to run a standalone AnyLogic Java app on a machine that does not have the latest Java version installed and due to company IT policies we will not be able to do so
Through some research I have found some sites to claim that they have already been doing it for Windows and Mac.
Using a bundled JRE on OSX
https://wiki.openjdk.java.net/display/MacOSXPort/How+to+embed+a+.jre+bundle+in+your+Mac+app
http://www.intransitione.com/blog/take-java-to-app-store/
My issue is that most of these posts refer to bundling an app for Mac OS x and requires that the jar files be created in an IDE like Eclipse. But since I use AnyLogic the jar files gets exported without myself being able to intervene. What I need is to change the command line code that runs the jar files and currently looks like this:
java -Xdock:name="AnyLogic Model" -Dnativewindow.awt.nohidpi=true -cp com.anylogic.engine.jar:com.anylogic.engine.nl.jar:lib/database/querydsl/querydsl-sql-codegen-3.6.3.jar -Xmx256m model6.Simulation $*
(Note: Code reduced for readability)
into something that I assume will pass the jre or JVM to be used as an argument to the java call. Or maybe set the directory to be used for java or something... as calling the java command on a machine without java installed renders nothing.
I have a very simple app, as well as a jdk plugin that I got from the moneydance app, which is a java app that runs on OSx with its own embedded jre, available here
https://www.dropbox.com/sh/1bedimsb0lj403t/AADYR7iFoBD4YiqS_RGZ2xAVa?dl=0
Thanks
A colleague of mine who is not on Stack Exchange gave me the answer so here goes, actually quite easy:
In order to meet my specific circumstances one just needs to include a jre inside the root of the folder that you supply to a client and then reference the the java executable in the execution file. The solution for Windows and Mac are slightly different so here goes:
On Mac
You can find the jre in the following folder. It is a hidden folder so if you Mac is not set to show hidded folders go to finder use command-shift-g and go to
/Library/Java/JavaVirtualMachines/
there should be a jdk folder and then navigate to
jdk1.8.0_45.jdk/Contents/Home/jre
On Windows
The location of the jre is in
c:\Program Files\Java\
you can see the location in the .bat file that AnyLogic creates automatically in line of code that looks like this:
#SET PATH_XJAL="%DISK_XJAL%\Program Files\Java\jre6\bin\java.exe"
Once you have the jre copy this folder to the same location as the stand alone java app. Then the only thing that remains is to change the referenced location in both mac command line executable and the windows.bat file
On Mac
Change from
java -Xdock:name="AnyLogic Model"
to
./jre/bin/java -Xdock:name="AnyLogic Model"
On Windows
Change from
#SET PATH_XJAL="%DISK_XJAL%\Program Files\Java\jre6\bin\java.exe"
to
#SET PATH_XJAL= \jre6\bin\java.exe"
Running the java app on both Mac and Windows will now be independent from the Java version on the machine or whether it is installed or not
another alternative is to compile your compiled application into an executable using Exe4J. It is not free but another advantage is that you send your client only a single exe-file, not a bunch of files. (Disclaimer: not tried with the internal AL7-dbase yet but it works fine when accessing external data).

Deploying basic java app for distribution

I created a java text based game. I exported it as a runnable jar file in eclipse, but double clicking didn't work to run it (not sure why this is, would appreciate an explanation) so I created a .bat file which has:
java -jar game.jar
This works on some computers. However, when a user who doesn't have java in their PATH (I assume this is the reason) runs the .bat file, it comes up with the error:
java is not recognized as an internal or external command
How can I make my java game able to run on all computers that have java (1.6) installed?
java -jar <your-jar> is, I think, the best you can do, if you want to support different operating systems as well. If a user doesn't have java command in the path, java support has not been installed as a public JRE and user should either fix the configuration or explicitly specify which private JRE is to be used. Oracle documentation explicitly states about the public JRE that
You must set the PATH environment variable to point to JAVA_HOME\bin
(where JAVA_HOME is the location where you installed the public JRE)
to register the JRE.
so a user should do just that. You can, however, check if JAVA_HOME is set and if java exists in the path and provide informational error message if it is not.
If you're fine with only supporting windows, you can use various .exe packaging systems to ease the process for end user. See this, this and this thread for details.

Package java application without needing to modify PATH

I have a Java console application which I can package into a jar file using IntelliJ, and can run the program with a bat or cmd file which has the following command:
java -jar main.jar
The problem with this is that my development machine (Windows) has the JAVA_HOME and PATH modified so that this works without issue.
Is there a way so that I can package the jar so that it can be opened without needing to modify the PATH?
I've tried looking all over and found questions on SO and other sites relating to building the jar, but it seems like all of these still require modifying the PATH variable.
Java's documentation says:
Making changes to the system PATH variable is not typically necessary for computers running Windows or Mac OS X. The instructions below are intended for advanced users or system administrators only.
If this is the case then how can others run the program if they are not an "advanced user" or "system administrator"?
Edit:
As an aside, I know this is possible because some jar files, like those which use the Swing framework are able to be run by just double-clicking on the jar and then the application opens.
Edit 2:
This article seems to be along the right path.
Edit 3:
This is kinda what I was looking for, however, it didn't work for me. The command I was trying on my existing jar was jar uvfm main.jar manifest.txt which returned updated manifest, but changed nothing.
No you cannot. They are system variables. The best thing to do is to write a shell script that will set these variables.
no. It should be able to understand 'java' command. For this path need to be set. But if you are planning to shift your jar as an application, you need to ship jre as well with your application. But i dont think this is what you want

jar to exe convert problem

hi i converted my jar file into an exe using jsmooth but when i install it, it shows an error like java not found.
Please help me, how can I add the jre to my exe wrapper so this problem is solved.
It is trying to get the java installation to run your application, where it might be searching in JAVA_HOME, So if the JAVA_HOME is not set in the machine where you installing your application then try to install the java and set the JAVA_HOME as a pre-requisite of your installation.
I don't believe JSmooth can actually bundle a JRE with the exe. What you can do is tell JSmooth where to expect the JRE when running the exe (as in the same folder the exe is run from). If you do this you simply need to zip the exe and a JRE up, and distribute that.
The end user would unzip this, and the resulting folder would contain your exe and the JRE. Since JSmooth knows where to look relative your exe, it can find the JRE.
i have use it using launch4j
follow the following steps
1-create project directory called e.g:project
2-copy the runnable jar file to it
3-copy the jre directory to it u can rename it or keep name as it e.g i will call myjre
run launch4j program :
1- fill the basic tap with required information .
2- go to JRE tap there is a field called (bundle JRE path ) write "myjre" add min Jar virsion 1,6 it will case you an error if you do not fill this fields
and then click run button to generate exe file , you have to remember to keep the myjre directory with along side with executable exe file
e.g the application directory should contains :
1- [you app name].exe
2-myjre
in this description you can run your application with no care if jre is installed in a machine or not and become portable
Good Luck , feel free to contact me for more details

Categories