在基于JDK8的主机系统上尝试在docker-compose中将jenkins-jdk11
连接到运行相同网络的nexus3
容器时遇到以下错误。单击“测试连接”后
错误:
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
似乎是问题所在,以及如何成功连接到Nexus?
答案 0 :(得分:1)
问题在于Jenkins和nexus使用的Java版本冲突,请确保将Java环境设置为与java -version相同,如下所示
java -version openjdk版本“ 11.0.8” 2020-07-14 OpenJDK运行时环境(内部版本11.0.8 + 10-post-Ubuntu-0ubuntu120.04) OpenJDK 64位服务器VM(内部版本11.0.8 + 10-post-Ubuntu-0ubuntu120.04,混合模式,共享)
cat / etc /环境 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”
这符合我的要求
答案 1 :(得分:0)
这是Jenkins Wiki上针对Java 11的Jenkins兼容性问题列出的一个问题。这是link。
一种可能的解决方案是在运行Jenkins时在JAVA_OPTS中添加-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory
。您可以通过使用--env
选项将env变量传递到容器来实现:
--env JAVA_OPTS=-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory
或者在docker中使用environment
进行构建:
services:
jenkins:
image: 'jenkins/jenkins:jdk11'
environment:
- JAVA_OPTS=-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory