问题描述
我们正在将我们的项目从Java 8迁移到Java11。其中一个API依赖于利用JAXB的库。我们知道JAXB已从JAVA 11中删除,我们开始将JAXB依赖项包括在库的POM中。
<!-- https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api -->
<!-- API -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<!-- Runtime -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
使用以下命令运行API项目时,一切正常
mvn spring-boot:run
但是,当API部署在质量检查服务器中并使用带有-的启动脚本启动时,
java -jar Sample-api-3.0.0-SNAPSHOT.jar
Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- 具有链接的异常:
[java.lang.classNotFoundException: com.sun.xml.bind.v2.ContextFactory] at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:269) at javax.xml.bind.ContextFinder.find(ContextFinder.java:412) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662) at com.eoriginal.ecore.client.documents.SearchDocumentHistoryAPI$RequestParameters.toMap(SearchDocumentHistoryAPI.java:344) ... 14 more Caused by: java.lang.classNotFoundException: com.sun.xml.bind.v2.ContextFactory at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.classLoader.loadClass(ClassLoader.java:522) at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122) at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155) at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:267)
更新: 我添加了Maven Shade插件来生成具有所有依赖项的JAR,但是当执行代码行以创建JAXBContext时,错误仍然存在- JAXBContext jaxbc = JAXBContext.newInstance(new Class [] {Abc.class});