博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How to change java version in Linux
阅读量:5896 次
发布时间:2019-06-19

本文共 2099 字,大约阅读时间需要 6 分钟。

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 .

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

你可能感兴趣的文章
mapper 传多个参数
查看>>
控制器
查看>>
树形dp poj1463
查看>>
wget 命令用法详解
查看>>
React(0.13) 定义一个checked组件
查看>>
Django - - 进阶 - - Django 中间件
查看>>
JS相关
查看>>
单例模式
查看>>
【C语言学习】《C Primer Plus》第7章 C控制语句:分支与跳转
查看>>
按键的硬件消抖小结
查看>>
Neo4j之Cypher学习总结
查看>>
我在软件开发中应该注意的地方
查看>>
阿里云服务器(Ubuntu16.04 64位)的使用
查看>>
cobbler
查看>>
shell算术运算与进制运算
查看>>
spark2.3在window10当中来搭建python3的使用环境pyspark
查看>>
find命令
查看>>
rel是有进有出,out是只出不进
查看>>
update sharepoint 2013 cu error
查看>>
获取webpart方法以及连接字符串记录
查看>>