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
Java command line arguments are arguments that are passed to your program via a terminal or shell command. They make your Java program more configurable by giving users or scripts running your software a way to specify input parameters at run time.
The java command starts a Java application. It does this by starting a Java runtime environment, loading a specified class, and calling that class's main method. By default, the first argument without an option is the name of the class to be called.
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).
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