I am shipping a executable jar file to customer, Customer has installed JRE 5, JRE 6 and JRE 7 on the box. My Jar required JRE 7 to run. Without changing the system PATH (Environment var) how can I specify the JRE 7 to use?
Java Runtime Environment (To Run The file) If you want to run the JAR file, you will need the Java Runtime Environment. If you have the Java Runtime Environment, then all you need to do is to double click on the file name. But it will only work if that particular file is executable.
You need a JRE but not the JDK. The JRE is the java runtime environment and java code cannot be executed without it. The . jar is a compiled java file can and this needs the java runtime environment to be run.
No, you can't. To run an executable jar you need a JRE. Current best practices for distributing Java applications is to bundle a compatible JRE with your application. The JDK tools jink and jpackage help create JRE images and native installers with executables that will launch the embedded JRE and run the Java code.
You can specify full path to that JRE that you need, for example:
/path/to/jre/bin/java.exe -jar executable.jar
or
/path/to/jre/bin/javaw.exe -jar executable.jar
If you run this from a shell (script) then it is good practice to first set the JAVA_HOME
environment variable to the right location before (/path/to/jre
) before running the executable. You could first set/export JAVA_HOME
and then extend it to the location of the Java executable (e.g. %JAVA_HOME%\bin\java.exe
on Windows). More information here.
I'm not sure there's a cross-platform way to achieve this.
On Windows you can use a tool such as launch4j to wrap up the jar as a .exe
that can select an appropriate JRE.
On Mac OS X you can have several different JDKs installed in parallel but only one public JRE (which will be at least the latest version out of the installed JDKs, and may be newer if it's been auto updated). It's the public JRE that is used for app bundles and when double clicking a JAR in finder.
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