简体   繁体   English

如何使用maven的jaxb_commons插件

[英]How to use jaxb_commons plugins from maven

I'm trying to use a jaxb plugin to insert a interface into a choice element generating the classes from maven. 我正在尝试使用jaxb插件将接口插入到从maven生成类的choice元素中。 The problem is that I can't seem to figure out how to do so from maven, the repository isn't clear from the documentation and the only example (bellow) doesn't work, it seems to ignore the plugin (maven reports no error about not finding it) or the plugin doesn't have all the adds-ons currently listed in the project documentation: 问题是我似乎无法从maven中弄清楚如何这样做,文档中的存储库并不清楚,唯一的例子(下图)不起作用,它似乎忽略了插件(maven报告没有关于没有找到它的错误)或者插件没有项目文档中当前列出的所有附加组件:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.6.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <generatePackage>br.com.wonder.nfe.xml</generatePackage>
        <args>
            <arg>-Xifins</arg>
        </args>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>basic</artifactId>
                <version>0.4.1.5</version>
            </plugin>
        </plugins>
    </configuration>
</plugin>

I have these in the root pom: 我在根pom中有这些:

<pluginRepositories>
    <pluginRepository>
        <id>maven2-repository.dev.java.net</id>
        <url>http://download.java.net/maven/2</url>
    </pluginRepository>
    <pluginRepository>
        <id>maven-repository.dev.java.net</id>
        <name>Java.net Maven 1 Repository (legacy)</name>
        <url>http://download.java.net/maven/1</url>
        <layout>legacy</layout>
    </pluginRepository>
</pluginRepositories>

Running that gives: 运行时给出:

Error while setting CmdLine options '[-Xifins, -episode, /home/administrador/JavaApp/wnfe3/wnfe-ejb/target/generated-sources/xjc/META-INF/sun-jaxb.episode]'! 设置CmdLine选项时出错'[-Xifins,-episode,/ home / adminminrad / JavaApp /wnfe3 / winfe-ejb / target / generator-sources / xjc / MARKA-INF / sun-jaxb.episode]'!

Embedded error: unrecognized parameter -Xifins 嵌入式错误:无法识别的参数-Xifins

Unfortunately, it looks like the interface injection plugin is no longer well supported. 不幸的是,看起来接口注入插件不再受到良好支持。 In fact, I'm having trouble finding the JAR for download. 事实上,我无法找到下载的JAR。

Thankfully, the JAXB2 Basics Plugins provides a similar mechanism for adding an interface to the generated JAXB stubs (see the Inheritance plugin ). 值得庆幸的是, JAXB2 Basics插件提供了一种类似的机制,用于向生成的JAXB存根添加接口(请参阅继承插件 )。

The JAXB2 Basics plugin is available in the java.net Maven repository. JAXB2 Basics插件可在java.net Maven存储库中找到。

Using the Inheritance plugin, your POM will look like: 使用继承插件,您的POM将如下所示:

<build>
  <plugins>
    <plugin>
      <groupId>org.jvnet.jaxb2.maven2</groupId>
      <artifactId>maven-jaxb2-plugin</artifactId>
      <version>0.6.2</version>
      <executions>
        <execution>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <extension>true</extension>
        <args>
          <arg>-Xinheritance</arg>
        </args>
        <plugins>
          <plugin>
            <groupId>org.jvnet.jaxb2_commons</groupId>
               <artifactId>jaxb2-basics</artifactId>
               <version>0.5.3</version>
           </plugin>
        </plugins>
      </configuration>
    </plugin>
    ...
  </plugins>
  ...
</build>

The Inheritance plugin documentation has an example for what your JAXB Bindings would look like. 继承插件文档有一个示例,说明了JAXB绑定的外观。 For your convenience, I've reproduced the example below: 为方便起见,我再现了以下示例:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
    jaxb:version="2.1"
    jaxb:extensionBindingPrefixes="inheritance">

    <!-- ... -->

    <xs:complexType name="WillBeMadeCloneableType">
        <xs:annotation>
            <xs:appinfo>
                <inheritance:implements>java.lang.Cloneable</inheritance:implements>
            </xs:appinfo>
        </xs:annotation>
        <!-- ... -->
    </xs:complexType>
    <!-- ... -->
</xs:schema>

I'm really not sure this is the "right" way to solve this but, this is what I did. 我真的不确定这是解决这个问题的“正确”方法,但这就是我所做的。 First, download the Interface Insertion Plugin xjc-if-ins.jar from https://jaxb2-commons.dev.java.net/interface-insertion/xjc-if-ins.jar (couldn't find a jar containing IfInsertPluginImpl.class in the java.net maven repository). 首先,从https://jaxb2-commons.dev.java.net/interface-insertion/xjc-if-ins.jar下载接口插入插件xjc-if-ins.jar (找不到包含IfInsertPluginImpl.class的jar IfInsertPluginImpl.class在java.net Maven仓库)。

Then, install the jar in the local repository: 然后,在本地存储库中安装jar:

mvn install:install-file -DgroupId=org.jvnet.jaxb2_commons \
                         -DartifactId=xjc-if-ins \
                         -Dversion=1.0-SNAPSHOT \
                         -Dpackaging=jar \
                         -Dfile=xjc-if-ins.jar

Finally, add the jar as a dependency of the maven-jaxb2-plugin in the plugin section: 最后,将jar添加为插件部分中maven-jaxb2-plugin的依赖项:

<build>
  <plugins>
    <plugin>
      <groupId>org.jvnet.jaxb2.maven2</groupId>
      <artifactId>maven-jaxb2-plugin</artifactId>
      <version>0.6.2</version>
      <executions>
        <execution>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <extension>true</extension>
        <args>
          <arg>-Xifins</arg>
        </args>
        <plugins>
          <plugin>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>basic</artifactId>
            <version>0.4.1.5</version>
          </plugin>
        </plugins>
      </configuration>
      <dependencies>
        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>xjc-if-ins</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
      </dependencies>
    </plugin>
    ...
  </plugins>
  ...
</build>

As I said, this is maybe not the cleanest way to configure the jaxb2 plugin to use the Interface Insertion Plugin but, with this setup, the generate goal doesn't complain about the -Xifins extension. 正如我所说,这可能不是配置jaxb2插件以使用Interface Insertion Plugin的最简洁方法,但是,通过此设置, generate目标不会抱怨-Xifins扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM