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.

How to change java version in Linux的更多相关文章

  1. 解决linux下javac -version和java -version版本显示不一致

    解决linux下javac -version和java -version版本显示不一致 [javascript] view plaincopy [root@localhost usr]# $JAVA_ ...

  2. linux JAVA_HOME和 java -version不匹配

    ~/.bashrc 中更新了jdk, JAVA_HOME 起效果了,但是java -version还是老的. 原因是/usr/bin/java   和usr/bin/javac是一个链接,得改. 使用 ...

  3. Linux更换jdk版本,java -version还是原来的版本问题

    服务器上默认安装版本是: 使用jenkins最新的安装包 2.73.1,启动报错52.0!需要使用1.8进行启动. 两种方式,要么tomcat直接指定,要么修改环境变量,这里我使用修改安装java版本 ...

  4. [非原创]Project facet Java version 1.8 is not supported解决记录

    原博地址:http://blog.csdn.net/dingchenxixi/article/details/51496998 一看知道是因为jdk版本不一致所导致,如何解决? 方法一: 选中项目 P ...

  5. Project facet Java version 1.8 is not supported解决记录

    一看知道是因为jdk版本不一致所导致,如何解决? 方法一: 选中项目 Properties , 选择 Project Facets,右击选择 Java , Change Version  方法二: 在 ...

  6. eclipse Project facet Java version 1.8 is not supported.

    在移植eclipse项目时,如果遇到 “Project facet Java version 1.7 is not supported.” 项目中的jdk1.7不支持.说明项目是其他版本jdk编译的, ...

  7. 运行java -version报cannot restore segment prot after reloc: Permission denied

    linux 安装jdk1.6后,运行java -version,没有出现相关的版本信息,而是出现了以下错误: dl failure on line 685Error: failed /usr/loca ...

  8. 项目移植过程中报:“Project facet Java version 1.7 is not supported.” 错误

    转载: http://my.oschina.net/nly/blog/349081 在移植eclipse项目时,如果遇到 报:“Project facet Java version 1.7 is no ...

  9. ubuntu中安装jdk 分类: java 学习笔记 linux ubuntu 2015-07-06 17:49 74人阅读 评论(0) 收藏

    参考文献:ubuntu 13.04 安装 JDK 先去oracle官网下载jdk,这一段我就不赘述了. 下载好之后先解压,解压方式参见 linux常用的压缩与解压缩命令 ,解压之后,将文件剪贴至/us ...

随机推荐

  1. 使用centos 5.x 64位系统安装astgo 2014 v7.3教程(含全套安装文件)

    版本特色: 全自动安装 安装过程中不用频繁输入yes或回车 自带完整号码归属地数据库 自带触屏版WAP ·首先确定你需要使用astgo 2014 7.0还是7.3: astgo 2014 v 7.0 ...

  2. 5.3QBXT模拟赛

    出题人:钟惠兴 题目名称 讨厌整除的小明 吸血鬼 鱼的感恩 题目类型 传统型 传统型 传统型 题目目录/可执行文件名 ming vamp fool 输入文件名 ming.in vamp.in fool ...

  3. 页面渐进式消失【JS代码】

    // 设定时间,页面慢慢变透明,直到消失 var opacityInterval = setInterval(function () { // 普通时间转为格林威治时间 var targetDate ...

  4. [python] ThreadPoolExecutor线程池

    初识 Python中已经有了threading模块,为什么还需要线程池呢,线程池又是什么东西呢?在介绍线程同步的信号量机制的时候,举得例子是爬虫的例子,需要控制同时爬取的线程数,例子中创建了20个线程 ...

  5. 【BZOJ1124】[POI2008]枪战Maf(基环树_构造)

    被教练勒令做题不能看题解后的第一道新题,自行 yy 了好久终于 AC 了(菜啊)--写博客纪念. 题目: BZOJ1124 分析: 考虑每个人向他要打的人连边.根据题意,所有点都有且只有一条出边.那么 ...

  6. vmware workstation 14 黑屏处理方法

    从12升级到14以后,所有老的虚拟系统全部黑屏.进行了一波操作,例如:虚拟机-管理-更改硬件兼容性,选择14.黑屏将加速3D图形勾选去掉:启动,关闭,再勾选上,启动.黑屏将显示器选择为指定监视器,黑屏 ...

  7. Spring Cloud (11) Hystrix-监控聚合监控

    上一篇利用Hystrix Dashboard去监控断路器的Hystrix command,当我们有很多服务的时候,就需要聚合所有服务的Hystrix Dashboard数据了,这就需要Hystrix ...

  8. CF126B Password

    思路: kmp略作修改. 实现: #include <iostream> #include <cstdio> using namespace std; ; int neXt[M ...

  9. Hive扩展功能(三)--使用UDF函数将Hive中的数据插入MySQL中

    软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这五部机, 每部主机的用户名都为centos ...

  10. 清瘦的记录者: 一个比dbutils更小巧、好用的的持久化工具

    https://gitee.com/bitprince/memory 1. 概述 1.1 连接.语句和结果集 从JDBC的规范上看,其对数据访问层有相当简洁的抽象:1.连接(connection) 2 ...