简体   繁体   中英

how to specify JRE to run a executable jar

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?

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 (eg %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.

The simplest way to do this, is to use Java WebStart to launch your program and then specify you need a suitably new version of Java. The launcher will then locate a suitable distribution on your system to use.

Using javaws also allows you to easily distribute new updates to your users.

Caveat: Caching has notoriously been a problem over the years. Ensure that when a jar changes content, its URL changes too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM