3

I use some programs that have known bugs when using Java 1.7.x (default on my computer), issues that would be fixed using Java 1.6. However I also use program that works fine with the default Java and have known issues with older versions.

How can I run the program myprogram specifing the version of Java to use?

lucacerone
  • 1,690

1 Answers1

1

There is a shell environment variable, JAVA_HOME that can be set to use a java version from a specific directory. It needs to be exported, and should contain the path of the bin subdirectory of the java version. Also, the same directory should be first (or before /usr/bin) in PATH.

The variable can be set in a script used to start an individual program.

You could find the bin directories of installed versions using something like

$ locate -b '\appletviewer'

For details on setting the variable, see Setting JAVA_HOME.

There is a similar variable JDK_HOME for the JDK.

Volker Siegel
  • 13,065
  • 5
  • 49
  • 65
  • I tried to set these, but the software seems to use the system version... – lucacerone Dec 16 '14 at 10:23
  • I just did this: created a bash script and before calling the program I set:

    export JAVA_HOME='pathtojavaversionbin'

    – lucacerone Dec 16 '14 at 10:24
  • Can you show your exact command, and the output of echo $PATH? Append it to the question as additional details - in a comment, it is not very readable. – Volker Siegel Dec 16 '14 at 11:09
  • 1
    JAVA_HOME doesn't strictly need to be exported. JAVA_HOME='pathtojavaversionbin' /path/to/command works fine – Auspex May 29 '19 at 15:11