Java 我应该在我的 Maven 项目中为 JAXB RI 使用哪些工件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26413431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which artifacts should I use for JAXB RI in my Maven project?
提问by lexicore
Historically, I always used the following JAXB RI artifacts in my Maven projects:
从历史上看,我总是在我的 Maven 项目中使用以下 JAXB RI 工件:
com.sun.xml.bind:jaxb-impl
- Runtimecom.sun.xml.bind:jaxb-xjc
- Schema compilercom.sun.xml.bind:jaxb-jxc
- Schema generator
com.sun.xml.bind:jaxb-impl
- 运行com.sun.xml.bind:jaxb-xjc
- 架构编译器com.sun.xml.bind:jaxb-jxc
- 模式生成器
Since approximately version 2.2.10*
these artifacts are now described as "old":
由于大约版本2.2.10*
这些工件现在被描述为“旧”:
com.sun.xml.bind:jaxb-impl
Old JAXB Runtime module.
com.sun.xml.bind:jaxb-impl
旧的 JAXB 运行时模块。
So it looks like these artifacts are now obsolete.
所以看起来这些文物现在已经过时了。
The question is:
问题是:
Which artifacts should be used instead?
应该使用哪些工件?
采纳答案by lexicore
After clarification with Oracle, the following artifacts should be used:
在与 Oracle 澄清后,应使用以下工件:
Runtime
运行
If you want to unmarshal XML to Java objects or marshal Java objects as XML:
如果要将 XML 解组为 Java 对象或将 Java 对象编组为 XML:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>...</version>
</dependency>
Schema compiler (XJC)
模式编译器 (XJC)
If you have an XML Schema and want to generate the Java code out of it:
如果您有一个 XML 模式并想从中生成 Java 代码:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>...</version>
</dependency>
Schema generator (JXC/schemagen
)
模式生成器 (JXC/ schemagen
)
If you have Java classes with JAXB annotations and want to generate a XML Schema based on them:
如果您有带有 JAXB 注释的 Java 类并希望基于它们生成 XML 模式:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-jxc</artifactId>
<version>...</version>
</dependency>
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.
后两个工件 (org.glassfish.jaxb:jaxb-xjc
和org.glassfish.jaxb:jaxb-jxc
) 由 Maven 插件包装,因此您通常在运行时不需要它们。
Eclipse usage
Eclipse 用法
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:
如果您的 Maven 项目不知何故没有获得完整的类路径,请打开调试输出并检查 Maven 控制台。您可能会在那里看到以下错误消息:
[ERROR] 'dependencyManagement.dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${tools.jar} @
[错误] com.sun:tools:jar 的“dependencyManagement.dependencies.dependency.systemPath”必须指定绝对路径,但它是 ${tools.jar} @
This is due to the following problem:
这是由于以下问题:
The solutionby @rustyx is to add -vm
option to the eclipse.ini
:
@rustyx的解决方案是向以下-vm
选项添加选项eclipse.ini
:
-vm
<PATH_TO_JDK>\jre\bin\javaw.exe