1 回答

TA貢獻1883條經驗 獲得超3個贊
嵌套異常是java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
簡而言之:隨著 Java 9 的發布,所需的依賴項已從 JDK 中刪除。如果您使用 Java 8 JDK 啟動應用程序,則會提供依賴項并且您的應用程序可以正常運行。如果您使用 Java 9 JDK 或更高版本啟動應用程序,則依賴項將不再存在并且無法啟動。
修復此問題的正確解決方案是將所需的依賴項添加到您的項目中:
dependencies {
? ? // JAX-B dependencies for JDK 9+
? ? implementation "javax.xml.bind:jaxb-api:2.2.11"
? ? implementation "com.sun.xml.bind:jaxb-core:2.2.11"
? ? implementation "com.sun.xml.bind:jaxb-impl:2.2.11"
? ? implementation "javax.activation:activation:1.1.1"
}
Maven 依賴項
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>javax.xml.bind</groupId>
? ? ? ? ? ? <artifactId>jaxb-api</artifactId>
? ? ? ? ? ? <version>2.2.11</version>
? ? ? ? </dependency>
? ? ? ? <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>com.sun.xml.bind</groupId>
? ? ? ? ? ? <artifactId>jaxb-core</artifactId>
? ? ? ? ? ? <version>2.2.11</version>
? ? ? ? </dependency>
? ? ? ? <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl -->
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>com.sun.xml.bind</groupId>
? ? ? ? ? ? <artifactId>jaxb-impl</artifactId>
? ? ? ? ? ? <version>2.2.11</version>
? ? ? ? </dependency>
? ? ? ? <!-- https://mvnrepository.com/artifact/javax.activation/activation -->
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>javax.activation</groupId>
? ? ? ? ? ? <artifactId>activation</artifactId>
? ? ? ? ? ? <version>1.1.1</version>
? ? ? ? </dependency>
添加回答
舉報