intellij-idea - 如何将 JAXB 导入 Java 11 IntelliJ (Gradle) 项目?

标签 intellij-idea jaxb java-11

我一直在使用 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/

相关文章:

java - 我需要编码到 XML 我的 XML 文件中出现重复值

java - 带有 jlink 创建运行时的 SSLHandshakeException

java - 为什么 getResource() 方法在 JDK 11 中返回 null?

intellij-idea - IntelliJ IDEA 错误 : cannot find vm options file

java - 安装了无限强度 jar 的非法 key 大小或默认参数

java - Jaxb2Marshaller 无法通过 xsd 架构序列化 POJO : "cannot find the declaration of element"

java - 如何用Java11解析 "The type com.sun.crypto.provider.SunJCE is not accessible"?

intellij-idea - 强制 IntelliJ 中的代码格式化程序加入行

intellij-idea - Cucumber-java 测试步骤在 IntelliJ 中执行两次

java - 如何在解码时捕获多次出现的 xml 到 pojo?