web-dev-qa-db-ja.com

javax.xml.bind.JAXBException JAXB-APIの実装がモジュールパスまたはクラスパスで見つかりませんでした

Spring BootアプリケーションをJava 9で実行しようとしていますが、ガイドに記載されているJAXBの問題に直面しましたが、うまくいきませんでした。 JAXB APIへの依存関係を追加し、アプリケーションが動作を開始しました。 Java version> = 9を使用したJAXB実装の欠落の結果として、次の例外が発生した場合:

javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.Java:177) ~[jaxb-api-2.3.0.jar:2.3.0]
    at javax.xml.bind.ContextFinder.find(ContextFinder.Java:364) ~[jaxb-api-2.3.0.jar:2.3.0]
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.Java:508) ~[jaxb-api-2.3.0.jar:2.3.0]
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.Java:465) ~[jaxb-api-2.3.0.jar:2.3.0]
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.Java:366) ~[jaxb-api-2.3.0.jar:2.3.0]
    at com.Sun.jersey.server.impl.wadl.WadlApplicationContextImpl.<init>(WadlApplicationContextImpl.Java:107) ~[jersey-server-1.19.1.jar:1.19.1]
    at com.Sun.jersey.server.impl.wadl.WadlFactory.init(WadlFactory.Java:100) [jersey-server-1.19.1.jar:1.19.1]
    at com.Sun.jersey.server.impl.application.RootResourceUriRules.initWadl(RootResourceUriRules.Java:169) [jersey-server-1.19.1.jar:1.19.1]
    at com.Sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.Java:106) [jersey-server-1.19.1.jar:1.19.1]
    at com.Sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.Java:1359) [jersey-server-1.19.1.jar:1.19.1]
    at com.Sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.Java:180) [jersey-server-1.19.1.jar:1.19.1]
    at com.Sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.Java:799) [jersey-server-1.19.1.jar:1.19.1]
    at com.Sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.Java:795) [jersey-server-1.19.1.jar:1.19.1]
    at com.Sun.jersey.spi.inject.Errors.processWithErrors(Errors.Java:193) [jersey-core-1.19.1.jar:1.19.1]
    at com.Sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.Java:795) [jersey-server-1.19.1.jar:1.19.1]
    at com.Sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.Java:790) [jersey-server-1.19.1.jar:1.19.1]
    at com.Sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.Java:509) [jersey-servlet-1.19.1.jar:1.19.1]
    at com.Sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.Java:339) [jersey-servlet-1.19.1.jar:1.19.1]
    at com.Sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.Java:605) [jersey-servlet-1.19.1.jar:1.19.1]
    at com.Sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.Java:207) [jersey-servlet-1.19.1.jar:1.19.1]
    at com.Sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.Java:394) [jersey-servlet-1.19.1.jar:1.19.1]
    at com.Sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.Java:744) [jersey-servlet-1.19.1.jar:1.19.1]
    at org.Apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.Java:270) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.Java:106) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.StandardContext.filterStart(StandardContext.Java:4491) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.StandardContext.startInternal(StandardContext.Java:5135) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:183) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1427) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1417) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at Java.base/Java.util.concurrent.FutureTask.run(FutureTask.Java:264) [na:na]
    at org.Apache.Tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.Java:75) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at Java.base/Java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.Java:140) [na:na]
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:943) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.StandardHost.startInternal(StandardHost.Java:839) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:183) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1427) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.Java:1417) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at Java.base/Java.util.concurrent.FutureTask.run(FutureTask.Java:264) [na:na]
    at org.Apache.Tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.Java:75) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at Java.base/Java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.Java:140) [na:na]
    at org.Apache.catalina.core.ContainerBase.startInternal(ContainerBase.Java:943) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.StandardEngine.startInternal(StandardEngine.Java:258) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:183) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.StandardService.startInternal(StandardService.Java:422) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:183) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.core.StandardServer.startInternal(StandardServer.Java:770) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.util.LifecycleBase.start(LifecycleBase.Java:183) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.Apache.catalina.startup.Tomcat.start(Tomcat.Java:371) [Tomcat-embed-core-9.0.10.jar:9.0.10]
    at org.springframework.boot.web.embedded.Tomcat.TomcatWebServer.initialize(TomcatWebServer.Java:107) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.boot.web.embedded.Tomcat.TomcatWebServer.<init>(TomcatWebServer.Java:86) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.boot.web.embedded.Tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.Java:413) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.boot.web.embedded.Tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.Java:174) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.Java:179) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.Java:152) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:542) [spring-context-5.1.0.RC1.jar:5.1.0.RC1]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.Java:140) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:769) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.Java:405) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:334) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1252) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1240) [spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at io.eureka.server.EurekaServerApp.main(EurekaServerApp.Java:21) [classes/:na]
    at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at Java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62) ~[na:na]
    at Java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[na:na]
    at Java.base/Java.lang.reflect.Method.invoke(Method.Java:564) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.Java:49) [spring-boot-devtools-2.1.0.M1.jar:2.1.0.M1]
Caused by: Java.lang.ClassNotFoundException: com.Sun.xml.internal.bind.v2.ContextFactory
    at org.springframework.boot.web.embedded.Tomcat.TomcatEmbeddedWebappClassLoader.loadClass(TomcatEmbeddedWebappClassLoader.Java:70) ~[spring-boot-2.1.0.M1.jar:2.1.0.M1]
    at org.Apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.Java:1138) ~[Tomcat-embed-core-9.0.10.jar:9.0.10]
    at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.Java:122) ~[jaxb-api-2.3.0.jar:2.3.0]
    at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.Java:155) ~[jaxb-api-2.3.0.jar:2.3.0]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.Java:174) ~[jaxb-api-2.3.0.jar:2.3.0]
    ... 66 common frames omitted
29
S34N

これらの依存関係をpom/gradleに追加します。

Gradle

compile('javax.xml.bind:jaxb-api:2.3.0')
compile('javax.activation:activation:1.1')
compile('org.glassfish.jaxb:jaxb-runtime:2.3.0')

Pom

<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0-b170201.1204</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.activation/activation -->
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.0-b170127.1453</version>
</dependency>
53
S34N