0

Background

I have a Jenkins server on Ubuntu 18.04 running Java version 11, checked by visiting /manage/systemInfo

java.specification.version 11

I have implemented docker build slaves based on Ubuntu 22.04 where I have specified that the java version should be 11:

# install java for Jenkins
RUN apt-get install -qy openjdk-11-jdk

I was wondering that all the build nodes stood as offline, and reading the log saw this:

Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

This question references List of Java class file format major version numbers? the Class versions:
52 is java 8
55 is java 11

and sure enough, a little further back in the log:

[11/14/22 18:35:38] [SSH] Checking java version of java
[11/14/22 18:35:38] [SSH] java -version returned 1.8.0_312.

so I went hunting for the culprit:

Attempts to find the culprit

sudo docker container exec 20e1bfe2b182 ls -l /usr/bin/java returned

/usr/bin/java -> /etc/alternatives/java

sudo docker container exec 20e1bfe2b182 ls -l /etc/alternatives/java returned

/etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java

and even injected RUN java -version into my Dockerfile before the line installing opendjk (which indicated no java was installed...)

On the host I have run apt list --installed |grep jdk

openjdk-11-jdk/bionic-updates,bionic-security,now 11.0.17+8-1ubuntu2~18.04 amd64 [installed]
openjdk-11-jdk-headless/bionic-updates,bionic-security,now 11.0.17+8-1ubuntu2~18.04 amd64 [installed]
openjdk-11-jre/bionic-updates,bionic-security,now 11.0.17+8-1ubuntu2~18.04 amd64 [installed]
openjdk-11-jre-headless/bionic-updates,bionic-security,now 11.0.17+8-1ubuntu2~18.04 amd64 [installed,automatic]

... the same command on the docker image gave similar results...
find -name java* 2>/dev/null run from / did not give anything useful either

which java output

HOST:

$ which java
/usr/bin/java $ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 Nov 24 2018 /usr/bin/java -> /etc/alternatives/java
$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 43 Jan 25 2022 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java

docker

$ sudo docker compose run man which java
/usr/bin/java
$ sudo docker compose run man ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 Nov 14 20:28 /usr/bin/java -> /etc/alternatives/java
$ sudo docker compose run man ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 43 Nov 14 20:28 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java

echo $PATH output

HOST

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

docker

$ sudo docker compose run man echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Potential workaround

Adding this to my Dockerfile seems to almost solve the issue:

RUN ln -s /usr/lib/jvm/java-11-openjdk-amd64/ /home/jenkins/jdk
RUN chown jenkins:jenkins /home/jenkins/jdk

Question

... so where does the JDK version 8 come from?

JoSSte
  • 2,953
  • 6
  • 34
  • 54
  • 1
    Since [2.361.1, 2022-09-07](https://www.jenkins.io/changelog-stable/#v2.361.1), Jenkins requires Java 11 (55) to run controller and agentsR. Run `which java` to determine which is really being picked up and `echo $PATH` to understand why getting 8. – Ian W Nov 15 '22 at 07:38
  • I actually tried `which java` first - and that only showed openjdk11 - I also tried echo $PATH to no avail either – JoSSte Nov 15 '22 at 08:56
  • Post the outputs of those commands. – Ian W Nov 15 '22 at 09:16
  • @JoSSte were u able to solve this issue ?? I am also facing the same issue and will be thankful if you can suggest a way – Karan Aug 15 '23 at 19:07
  • 1
    @Karan I did. you can see the definition of my build slave here: https://github.com/JoSSte/jenkins-build-slave-php/blob/master/Dockerfile As I recall it `FROM jenkins/inbound-agent:jdk11 as agent` was the key – JoSSte Aug 16 '23 at 09:25
  • 1
    Thanks a lot @JoSSte for sharing the solution. will check this approach also. currently, I was able to solve the same by some hack which I share in the answer below. the culprit was that it was having 2 JDK versions and it was picking always Java for 8 for some reasons – Karan Aug 16 '23 at 12:45

1 Answers1

1

i wasted 2 days in this and what i found was that my docker container which was running had Two JDK installed ( 1 was default centOS7 and the other was which i am adding in Dockerfile ). This was causing compatibility issues as DOCKER on my Host was running on JDK11 and the docker container( as a slave ) was picking the JDK8 as both Runtime environment was available there.

you can create and add a script inside your docker file to always select runtime of JDK11

RUN echo 2 | alternatives --config java
Karan
  • 443
  • 5
  • 14