Java Maven JAXB 插件的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2432859/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 07:34:51  来源:igfitidea点击:

Difference of Maven JAXB plugins

javamaven-2jaxbmavenmaven-plugin

提问by cuh

I have determined that two JAXBplugins for Maven2 exist, with some different configurations.

我已经确定存在用于Maven2 的两个JAXB插件,它们具有一些不同的配置。

The one is from Sun: http://jaxb.dev.java.net/jaxb-maven2-plugin/, the other from Mojohaus: http://mojohaus.org/jaxb2-maven-plugin/

一个来自 Sun:http://jaxb.dev.java.net/jaxb-maven2-plugin/,另一个来自 Mojohaus:http://mojohaus.org/jaxb2-maven-plugin/

Which of these two plugins can be recommended?

可以推荐这两个插件中的哪个?



Thanks Matt. On my little research project, I found that there's quite another plugin comming from the sunners:

谢谢马特。在我的小研究项目中,我发现还有一个来自 sunners 的插件:

<groupId>com.sun.tools.xjc.maven2</groupId>  
<artifactId>maven-jaxb-plugin</artifactId>  

and that one:

还有那个:

<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>

and still the one from Codehouse.

仍然是 Codehouse 的那个。

采纳答案by Pascal Thivent

Let's summarize. We have:

让我们总结一下。我们有:

  1. the maven-jaxb2-plugin(https://github.com/highsource/maven-jaxb2-plugin)
  2. the maven-jaxb-plugin(https://jaxb.dev.java.net/jaxb-maven2-plugin/)
  3. the jaxb2-maven-plugin(https://github.com/mojohaus/jaxb2-maven-plugin)
  1. Maven的JAXB2-插件https://github.com/highsource/maven-jaxb2-plugin
  2. Maven的JAXB的插件https://jaxb.dev.java.net/jaxb-maven2-plugin/
  3. 所述JAXB2-Maven的插件https://github.com/mojohaus/jaxb2-maven-plugin

Based on the comments of this thread, I've always used the maven-jaxb2-plugin(i.e. plugin #1):

根据该线程的评论,我一直使用maven-jaxb2-plugin(即插件 #1):

Concerning the org.jvnet.jaxb2.maven2:maven-jaxb2-plugin versus com.sun.tools.xjc.maven2:maven-jaxb-plugin, from my point of view it's definitely the first one (http://maven-jaxb2-plugin.java.net/).

This plugin has much more features than com.sun.tools.xjc.maven2:maven-jaxb-plugin, the development is active. Finally, I'm one of the authors :) and I'd say we keep in touch with JAXB developers and users and react to the latests features/requests.

关于 org.jvnet.jaxb2.maven2:maven-jaxb2-plugin 与 com.sun.tools.xjc.maven2:maven-jaxb-plugin,从我的角度来看,它绝对是第一个(http://maven-jaxb2 -plugin.java.net/)。

这个插件比 com.sun.tools.xjc.maven2:maven-jaxb-plugin 有更多的功能,正在开发中。最后,我是作者之一 :) 我想说我们与 JAXB 开发人员和用户保持联系,并对最新的功能/请求做出反应。

And indeed, the plugin #2 isn't very active (dead?). And because I've always been happy with #1, I've never used plugin #3 so can't really say anything about it. Just in case, here is a working configuration for plugin #1:

事实上,插件#2 不是很活跃(死了?)。因为我一直对#1 很满意,所以我从来没有使用过#3 插件,所以不能说任何关于它的事情。以防万一,这里是插件 #1 的工作配置:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <inherited>true</inherited>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

回答by matt b

I would guess that one is for the original JAXB specification and the codehaus one is for the JAXB 2.1 specification (and if the dev.java.net would load some time this century, I'd be able to say for sure).

我猜想一个是针对原始 JAXB 规范的,而 codehaus 一个是针对 JAXB 2.1 规范的(如果 dev.java.net 会在本世纪某个时候加载,我可以肯定地说)。

回答by lexicore

I am the author of maven-jaxb2-plugin.

我是maven-jaxb2-plugin 的作者

The maven-jaxb2-plugin currently uses JAXB 2.1. In the next versions we'll also provide JAXB 2.0 and JAXB 2.2 versions.

maven-jaxb2-plugin 当前使用 JAXB 2.1。在下一个版本中,我们还将提供 JAXB 2.0 和 JAXB 2.2 版本。

As for "which plugin is better" discussion, check the features, decide yourself. Let me know if you miss some functionality.

至于“哪个插件更好”的讨论,检查功能,自己决定。如果您错过了某些功能,请告诉我。

回答by Ed Staub

On a slight tangent: there was a problem with use of maven-jaxb2-plugin with Eclipse Indigo that I posted here. A fix (extension) has recently become available.

稍微说一下:在我在此处发布的 Eclipse Indigo 中使用 maven-jaxb2-plugin 时出现问题。最近有一个修复(扩展)可用。

This is not meant to disagree, at all, with the recommendation of maven-jaxb2-plugin over maven2-jaxb-plugin. I don't know, but I expect that maven2-jaxb-plugin has the same problem, probably unresolved.

这并不意味着不同意 maven-jaxb2-plugin 优于 maven2-jaxb-plugin 的建议。我不知道,但我希望 maven2-jaxb-plugin 有同样的问题,可能没有解决。

回答by bn.

I have recently tried the three plug-ins mentioned above (included here as well):

我最近尝试了上面提到的三个插件(也包括在这里):

  1. the maven-jaxb2-plugin (http://maven-jaxb2-plugin.java.net/)
  2. the maven-jaxb-plugin (https://jaxb.dev.java.net/jaxb-maven2-plugin/)
  3. the jaxb2-maven-plugin (http://mojo.codehaus.org/jaxb2-maven-plugin/)
  1. maven-jaxb2-plugin ( http://maven-jaxb2-plugin.java.net/)
  2. maven-jaxb-plugin ( https://jaxb.dev.java.net/jaxb-maven2-plugin/ )
  3. jaxb2-maven-plugin ( http://mojo.codehaus.org/jaxb2-maven-plugin/)

I ended up using a fourth option: The CXF XJC Maven Pluginhttp://cxf.apache.org/cxf-xjc-plugin.html

我最终使用了第四个选项:CXF XJC Maven 插件http://cxf.apache.org/cxf-xjc-plugin.html

If I am missing something I would like to know, but the configuration seemed more straightforward for what I was trying to do and more easily allowed me to to deal with duplicate class generation within the same namespace -- similar to this question: Is there a way to deal with duplicate element definitions across multiple .xsd files in JAXB?.

如果我遗漏了一些我想知道的信息,但是对于我想要做的事情,配置似乎更简单,并且更容易让我在同一个命名空间内处理重复的类生成——类似于这个问题:是否有一个在 JAXB 中处理跨多个 .xsd 文件的重复元素定义的方法?.

I now have granular control over each incoming XSD and corresponding java package; here is a sample configuration close to the one I am using.

我现在可以精细地控制每个传入的 XSD 和相应的 java 包;这是一个与我正在使用的配置接近的示例配置。

 <plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-xjc-plugin</artifactId>
    <version>2.3.0</version>
    <configuration>
        <extensions>
            <extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.3.0</extension>
        </extensions>
    </configuration>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>xsdtojava</goal>
            </goals>
            <configuration>
                <sourceRoot>${basedir}/target/generated-sources/src/main/java</sourceRoot>
                <xsdOptions>
                    <xsdOption>
                        <xsd>src/main/resources/schema/commands.xsd</xsd> <!--shares a common.xsd file causing the conflicts-->
                        <packagename>com.foo.bar.commands</packagename>
                    </xsdOption>
                    <xsdOption>
                        <xsd>src/main/resources/schema/responses.xsd</xsd>
                        <packagename>com.foo.bar.responses</packagename>
                    </xsdOption>
                </xsdOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

回答by rds

  • maven-jaxb2-plugin uses the JAXB reference implementation by Oracle/Sun
  • cxf and jaxb2-maven-plugin use Apache Xerces
  • maven-jaxb2-plugin 使用 Oracle/Sun 的 JAXB 参考实现
  • cxf 和 jaxb2-maven-plugin 使用 Apache Xerces