diff --git a/sources/tech/20151105 Linux FAQs with Answers--How to change default Java version on Linux.md b/sources/tech/20151105 Linux FAQs with Answers--How to change default Java version on Linux.md deleted file mode 100644 index 4280798d81..0000000000 --- a/sources/tech/20151105 Linux FAQs with Answers--How to change default Java version on Linux.md +++ /dev/null @@ -1,54 +0,0 @@ -translating----geekpi - -Linux FAQs with Answers--How to change default Java version on Linux -================================================================================ -> **Question**: When I am trying to run a Java program on Linux, I am getting the following error. Looks like the Java program is compiled for a different Java version than the default Java program installed on my Linux. How can I switch the default Java version on Linux? -> -> Exception in thread "main" java.lang.UnsupportedClassVersionError: com/xmodulo/hmon/gui/NetConf : Unsupported major.minor version 51.0 - -When a Java program is compiled, the build environment sets a "target" which is the oldest JRE version the program can support. If you run the Java program on a Linux system which does not meet the lowest JRE version requirement, you will encounter the following error while starting the program. - - Exception in thread "main" java.lang.UnsupportedClassVersionError: com/xmodulo/hmon/gui/NetConf : Unsupported major.minor version 51.0 - -For example, in this case the program is compiled for Java JRE 1.7 but the system only has Java JRE 1.6. - -To solve this problem, you need to change the default Java version you are using to Java JRE 1.7 or higher (assuming that such JRE is already installed). - -First, **check available Java versions** on your Linux system by using update-alternatives command: - - $ sudo update-alternatives --display java - -![](https://c2.staticflickr.com/6/5663/22661333316_81fe1ab7da_c.jpg) - -In this example, there are four different Java versions that are installed: OpenJDK JRE 1.6, Oracle Java JRE 1.6, OpenJDK JRE 1.7 and Oracle Java JRE 1.7. The default Java version is currently set to OpenJDK JRE 1.6. - -If the necessary Java JRE is not installed, you can always install it using [these instructions][1]. - -Now that there are suitable candidates to change to, you can **switch the default Java version** among available Java JREs by running the following command: - - $ sudo update-alternatives --config java - -When prompted, select the Java version you would like to use. In this example, we choose Oracle Java JRE 1.7. - -![](https://c2.staticflickr.com/6/5651/22066181083_b9c4c5b676_c.jpg) - -Now you can verify the default Java version as follows. - - $ java -version - -![](https://c1.staticflickr.com/1/634/22499411280_1d702a4101_c.jpg) - -Finally, if you defined JAVA_HOME environment variable somewhere, update the variable according to the newly set default Java version. - --------------------------------------------------------------------------------- - -via: http://ask.xmodulo.com/change-default-java-version-linux.html - -作者:[Dan Nanni][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://ask.xmodulo.com/author/nanni -[1]:http://ask.xmodulo.com/install-java-runtime-linux.html diff --git a/translated/tech/20151105 Linux FAQs with Answers--How to change default Java version on Linux.md b/translated/tech/20151105 Linux FAQs with Answers--How to change default Java version on Linux.md new file mode 100644 index 0000000000..c48274edf0 --- /dev/null +++ b/translated/tech/20151105 Linux FAQs with Answers--How to change default Java version on Linux.md @@ -0,0 +1,53 @@ +Linux又问必答-- 如何在Linux中改变默认的Java版本 +================================================================================ +> **提问**:当我尝试在Linux中运行一个Java程序时,我遇到了一个错误。看上去像程序编译所使用的Javab版本与我本地的不同。我该如何在Linux上切换默认的Java版本? + +> +> Exception in thread "main" java.lang.UnsupportedClassVersionError: com/xmodulo/hmon/gui/NetConf : Unsupported major.minor version 51.0 + +当Java程序编译时,编译环境会设置一个“target”变量来设置程序可以运行的最低Java版本。如果你Linux系统上运行的程序不满足最低的JRE版本要求,那么你会在运行的时候遇到下面的错误。 + + Exception in thread "main" java.lang.UnsupportedClassVersionError: com/xmodulo/hmon/gui/NetConf : Unsupported major.minor version 51.0 + +比如,这种情况下程序在Java JRE 1.7下编译,但是系统只有Java JRE 1.6。 + +要解决这个问题,你需要改变默认的Java版本到Java JRE 1.7或者更高(假设JRE已经安装了)。 + +首先,试用下面的update-alternatives命令**检查你系统上可用的Java版本**: + + $ sudo update-alternatives --display java + +![](https://c2.staticflickr.com/6/5663/22661333316_81fe1ab7da_c.jpg) + +本例中,总共安装了4个不同的Java版本:OpenJDK JRE 1.6、Oracle Java JRE 1.6、OpenJDK JRE 1.7 和 Oracle Java JRE 1.7。现在默认的Java版本是OpenJDK JRE 1.6。 + +如果没有安装需要的Java JRE,你可以参考[这些指导][1]来完成安装。 + +现在有可用的候选版本,你可以用下面的命令在可用的Java JRE之间**切换默认的Java版本**: + + $ sudo update-alternatives --config java + +看到提示的时候,选择你想试用的Java版本。本例中,我们选择Oracle Java JRE 1.7。 + +![](https://c2.staticflickr.com/6/5651/22066181083_b9c4c5b676_c.jpg) + +现在用下面的命令验证默认的Java版本。 + + $ java -version + +![](https://c1.staticflickr.com/1/634/22499411280_1d702a4101_c.jpg) + +最后,如果你定义了JAVA_HOME环境变量,根据你设置的Java版本更新变量。 + +-------------------------------------------------------------------------------- + +via: http://ask.xmodulo.com/change-default-java-version-linux.html + +作者:[Dan Nanni][a] +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://ask.xmodulo.com/author/nanni +[1]:http://ask.xmodulo.com/install-java-runtime-linux.html