问题:公司的tomcat用的是jdk1.7的,但自从jenkins2.54版本以上却只支持jdk1.8
linux中centos7.7服务器上oracle的jdk1.8,systemctl status jenkins提示
Stopped LSB: Jenkins Automation Server.
Jun 6 07:48:04 localhost systemd: Starting LSB: Jenkins Automation Server…
Jun 6 07:48:04 localhost jenkins: Starting Jenkins Jun 06, 2020 7:48:04 AM Main verifyJavaVersion
Jun 6 07:48:04 localhost jenkins: SEVERE: Running with Java class version 51, which is older than the Minimum required version 52. See https://jenkins.io/redirect/java-support/
Jun 6 07:48:04 localhost jenkins: java.lang.UnsupportedClassVersionError: 51.0
Jun 6 07:48:04 localhost jenkins: at Main.verifyJavaVersion(Main.java:182)
Jun 6 07:48:04 localhost jenkins: at Main.main(Main.java:142)
Jun 6 07:48:04 localhost jenkins: Jenkins requires Java versions [8, 11] but you are running with Java 1.7 from /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64/jre
Jun 6 07:48:04 localhost jenkins: java.lang.UnsupportedClassVersionError: 51.0
Jun 6 07:48:04 localhost jenkins: at Main.verifyJavaVersion(Main.java:182)
Jun 6 07:48:04 localhost jenkins: at Main.main(Main.java:142)
Jun 6 07:48:04 localhost jenkins: [ OK ]
Jun 6 07:48:05 localhost systemd: Started LSB: Jenkins Automation Server.
原因分析:
1、公司的jdk1.7版本不能换,不然影响业务软件兼容性,可能会出问题。
2、将jenkins换为支持jdk1.7的版本,实验结果:很多插件都只支持2.60版本以上的jenkins,导致大部分插件安装失败。
3、系统再安装一个jdk1.8的给jenkins专用,再修改启动文件的jdk路径即可。
linux下切换jdk版本
alternatives --config java (后输入版本前面的数字)
在这里插入图片描述
java -version (查看jdk的版本)
安装步骤:
1.官网下载jdk-8u191-linux-x64.tar.gz,安装到/usr/local/java-1.8/jdk1.8.0_191中
2.修改jenkins启动文件如下:(rpm包安装的jenkins)
vim /etc/init.d/jenkins
candidates="
/usr/local/java-1.8/jdk1.8.0_191/bin/java #echo $JAVA_HOME 将JAVA_HOME/bin/java加在此处
/usr/java/jdk1.7.0_75/bin/java
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/bin/java
"
添加jdk1.8的安装路径进去即可
结果:可行,系统原jdk不变,通过源码包安装的方式安装jdk1.8版本的再给jenkins指定路径实现。
优点:即不影响原有java项目,也能实现jenkins最新版的升级使用