How to change java version in Linux

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

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.

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.

Now you can verify the default Java version as follows.

$ java -version

Finally, if you defined JAVA_HOME environment variable somewhere, update the variable according to the newly set default Java version.

转载于:https://www.cnblogs.com/ngtest/p/9637864.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值