如何在特定 Java 版本上运行应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50463766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:37:53  来源:igfitidea点击:

How to run an application on a specific Java version?

javalinuxubuntu

提问by Socrates

How can I run an application with a specific Java version? I have three Java versions intstalled:

如何运行具有特定 Java 版本的应用程序?我安装了三个 Java 版本:

myuser@mysystem:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      auto mode
* 1            /opt/jdk-9.0.4/bin/java                          1         manual mode
  2            /opt/jdk1.8.0_162/bin/java                       1         manual mode
  3            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

I have Java 9 set as default and I'd like to keep it that way. Still, an application named pdfsamdoesn't seem to work properly with Java 9. What command is necessary to run it with openjdk (option 3)?

我将 Java 9 设置为默认值,我想保持这种状态。尽管如此,名为的应用程序pdfsam似乎无法在 Java 9 中正常工作。使用 openjdk(选项 3)运行它需要什么命令?

采纳答案by TomVW

You can run javawith the absolute path to the installation

您可以java使用安装的绝对路径运行

This would be your default /usr/bin/javainstallation

这将是您的默认/usr/bin/java安装

java -version

To change it, use the absolute path

要更改它,请使用绝对路径

/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -version

If you're not running the javacommand directly, try setting the JAVA_HOME variable:

如果您没有java直接运行该命令,请尝试设置 JAVA_HOME 变量:

JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/" pdfsam