在我的 Maven 项目中,我应该为 JAXB RI 使用哪些工件?
从历史上看,我总是在我的 Maven 项目中使用以下 JAXB RI 工件:
Historically, I always used the following JAXB RI artifacts in my Maven projects:
com.sun.xml.bind:jaxb-impl
- 运行时com.sun.xml.bind:jaxb-xjc
- 模式编译器com.sun.xml.bind:jaxb-jxc
- 模式生成器
com.sun.xml.bind:jaxb-impl
- Runtimecom.sun.xml.bind:jaxb-xjc
- Schema compilercom.sun.xml.bind:jaxb-jxc
- Schema generator
由于大约是 2.2.10*
版本,这些工件现在是 描述为旧":
Since approximately version 2.2.10*
these artifacts are now described as "old":
com.sun.xml.bind:jaxb-impl
旧的 JAXB 运行时模块.
Old JAXB Runtime module.
所以看起来这些工件现在已经过时了.
So it looks like these artifacts are now obsolete.
问题是:
应该使用哪些工件?
推荐答案
与Oracle澄清后,应使用以下工件:
After clarification with Oracle, the following artifacts should be used:
如果要将 XML 解组为 Java 对象或将 Java 对象编组为 XML:
If you want to unmarshal XML to Java objects or marshal Java objects as XML:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>...</version>
</dependency>
架构编译器 (XJC)
如果您有一个 XML Schema 并想从中生成 Java 代码:
Schema compiler (XJC)
If you have an XML Schema and want to generate the Java code out of it:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>...</version>
</dependency>
模式生成器(JXC/schemagen
)
如果您有带有 JAXB 注释的 Java 类并希望基于它们生成 XML Schema:
Schema generator (JXC/schemagen
)
If you have Java classes with JAXB annotations and want to generate a XML Schema based on them:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-jxc</artifactId>
<version>...</version>
</dependency>
后两个工件(org.glassfish.jaxb:jaxb-xjc
和 org.glassfish.jaxb:jaxb-jxc
)由 Maven 插件包装,因此您通常在运行时不需要它们.
The two latter artifacts (org.glassfish.jaxb:jaxb-xjc
and org.glassfish.jaxb:jaxb-jxc
) are wrapped by Maven plugins so you normally would not need them in the runtime.
如果您的 Maven 项目无法获得完整的类路径,请打开调试输出并检查 Maven 控制台.您可能会在此处看到以下错误消息:
If your Maven projects somehow don't get the full classpath, turn on debug output and check the Maven console. You might be seeing the following error message there:
[ERROR] 'dependencyManagement.dependencies.dependency.systemPath' for com.sun:tools:jar 必须指定绝对路径,但为 ${tools.jar} @
[ERROR] 'dependencyManagement.dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${tools.jar} @
这是由于以下问题:
Maven 没有正确选择 JAVA_HOME
@rustyx 的 解决方案 是将 -vm
选项添加到 eclipse.ini
:
The solution by @rustyx is to add -vm
option to the eclipse.ini
:
-vm
<PATH_TO_JDK>jreinjavaw.exe
相关文章