mCs
mCs

Reputation: 2921

Docker: Jenkins-jdk11 fails to connect to Nexus due to JAXB-API has not been found

Get the following error while trying to connect jenkins-jdk11 to nexus3 containers running same network in docker-compose on JDK8 based host system. Afer clicking "Test Connection" enter image description here

The error:

Nexus Repository Manager 3.x connection failed
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:278)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:421)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
    at com.sonatype.nexus.api.zz.ex.a(SourceFile:33)
    at com.sonatype.nexus.api.zz.ex.b(SourceFile:24)
    at com.sonatype.nexus.api.zz.ez.handleResponse(SourceFile:54)
    at org.apache.http.impl.client.CloseableHttpClient.execute(SourceFile:223)
    at org.apache.http.impl.client.CloseableHttpClient.execute(SourceFile:165)
    at com.sonatype.nexus.api.zz.et.a(SourceFile:84)
    at com.sonatype.nexus.api.zz.es.getVersion(SourceFile:126)
    at com.sonatype.nexus.api.repository.v3.RepositoryManagerV3Client$getVersion.call(Unknown Source)

docker-compose.yml

version: "3"
services:
  jenkins-jdk11:
    user: root
    image: 'jenkins/jenkins:jdk11'
    ports:
      - '10000:8080'
      - '50000:50000'
    environment:
      - TZ=Europe/Warsaw
      - "JAVA_OPTS=-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory"
    links:
      - nexus3
    volumes:
      - 'jenkins-data:/var/jenkins_home'
      - '/var/run/docker.sock:/var/run/docker.sock'
    deploy:
      restart_policy:
         condition: on-failure
    networks:
      - backend
  nexus3:
    container_name: nexus3
    image: 'sonatype/nexus3'
    ports:
      - '50001:8081'
    volumes:
      - 'local-nexus-data-volume:/nexus-data'
    networks:
      - backend
volumes:
  jenkins-data:
    driver: local
  local-nexus-data-volume:
    driver: local
networks:
  backend:
    driver: overlay

What seems to be the problem and how to successfully connect to Nexus?

EDIT My JAXB plugin installed: enter image description here

Upvotes: 0

Views: 2014

Answers (2)

Prudvi Raj
Prudvi Raj

Reputation: 11

The issue is with the conflict of java version been used by Jenkins & nexus make sure to set the Java environment as same as java -version as same below

java -version openjdk version "11.0.8" 2020-07-14 OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04) OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)

cat /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

#JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64"

this solved for me after going with this requirement

Upvotes: 1

Michał Krzywański
Michał Krzywański

Reputation: 16940

It is an issue listed on Jenkins wiki for Jenkins compatability issues with Java 11. Here is the link.

One possible solution is to add -Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory in the JAVA_OPTS while running Jenkins. You can do this by passing env variables to container using --env option :

--env JAVA_OPTS=-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory

Or in docker compose using environment :

services:
  jenkins:
    image: 'jenkins/jenkins:jdk11'
    environment:
     - JAVA_OPTS=-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory

Upvotes: 1

Related Questions