0

See also my related question.

Our Java application runs with Java 1.6 and higher, but we prefer 1.7 (because of certain additional features). When launching it how can I detect whether JRE 1.7 is installed and use an installed JRE 1.6 only as a fall-back? From the symlink-chain starting at which java it looks like the user only can decide for either Java 1.6 or 1.7.

Thomas S.
  • 753
  • 2
  • 13
  • 28

1 Answers1

1

When launching, you should use whatever the user has configured as the JRE on his system. If 1.7 is preferred strongly enough that you want to ignore the user's selected JRE and use 1.7, then you should just depend upon 1.7.

It's generally a rare scenario that a user has both 1.6 and 1.7 installed, and has java pointing to 1.6. If that's the case, they had to manually configure the symlink to point to 1.6, and you should respect that. If you install 1.7, by default the java link gets updated to point to 1.7.

Darth Android
  • 37,872
  • 5
  • 94
  • 112
  • +1, seems very reasonable. Informing the user of the situation and leaving the decision up to the user should be the right way to go in general. It also seems like the most fail-safe solution during future version upgrades and across different systems. – Daniel Andersson Jul 24 '13 at 18:48
  • Unfortunately, it is no rare scenario, because of a bug installing `openjdk-7-jre-headless`automatically installed `openjdk-6-jre-headless`... Also, the user might have switched its Java version to 1.6 because a different application needs it. – Thomas S. Jul 25 '13 at 09:51
  • @ThomasS. Your application's launch script should look at the value of the environmental variable `JAVA_HOME`, and the configuration for your application (which should be loaded by the launch script) should allow a user to override `JAVA_HOME` if they need to launch your program with a specific JRE. Otherwise, you should use whatever is configured as the default JRE on their system because that's what a user will expect. Take a look at how Eclipse and IntelliJ and most other major java programs on linux work. – Darth Android Jul 25 '13 at 14:20
  • @ThomasS. I didn't say it was rare to have two JREs, I said it was rare to have two JREs and for the `java` symlink to point to the older one. Newer JREs have higher-priority when the `java` symlink is set to auto-configure. My point is, if I have configured `java` to run JRE6, and I have not added additional configuration to your application to run with a different JRE, then you should run with JRE6, even if I have JRE7 or JRE8 installed. – Darth Android Jul 25 '13 at 14:23
  • Is JAVA_HOME ensured to be set by the different JRE bundles? – Thomas S. Jul 25 '13 at 15:40
  • @ThomasS. In my experience, no. It's supposed to be used in a "Does `JAVA_HOME` exist? Alright, it does, let's use that; otherwise, let's use the default JRE that the user has configured." It's for overriding. Java programs then allow the user to specify `JAVA_HOME` in the launch script if they want to persistently launch your application with something other than the default. – Darth Android Jul 25 '13 at 16:12