我一直在使用 JDK 8 的 Java 项目中使用 JAXB。
迁移到 JDK 11 后,不再识别 JAXB 包名称。
我也没有找到将 JAXB 添加为 gradle 中的依赖项的方法。
如何将 JAXB 导入到我的项目中?
最佳答案
您需要包含 JAXB API 并从 JAXB 实现之一中进行选择,因为 JDK 11 中默认不再包含 JAXB。您需要向 build.gradle
添加一些依赖项。 .
所以首先:
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
如果您决定使用例如 MOXy,则类似于:
compile group: 'org.eclipse.persistence', name: 'org.eclipse.persistence.moxy',
version: '2.7.3'
另见 this great explanation
这个使用 MOXy 的例子也需要
jaxb.properties
包含有关 JAXBContextFactory
信息的文件(见 here chapter 2.1):javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
这样做的好处似乎是:
Because you do not need to change any application code, you can easily switch between different JAXB implementations.
关于intellij-idea - 如何将 JAXB 导入 Java 11 IntelliJ (Gradle) 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54055620/