![](/img/trans.png)
[英]Java 11: Implementation of JAXB-API has not been found on module path or classpath
[英]Docker: Jenkins-jdk11 fails to connect to Nexus due to JAXB-API has not been found
嘗試將jenkins-jdk11
連接到在基於 JDK8 的主機系統上的 docker-compose 中運行相同網絡的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?
這是 Jenkins wiki 上列出的關於 Jenkins 與 Java 11 兼容性問題的問題。這是鏈接。
一種可能的解決方案是在運行 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 compose 中使用environment
:
services:
jenkins:
image: 'jenkins/jenkins:jdk11'
environment:
- JAVA_OPTS=-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory
問題在於 Jenkins 和 nexus 使用的 java 版本沖突,請確保將 Java 環境設置為與 java -version 相同,如下所示
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,混合模式,共享)
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"
在滿足此要求后,這為我解決了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.