Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.

share|improve this answer
+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-headlessautomatically 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 9: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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .