How to use jaxb_commons plugins from maven

*爱你&永不变心* 提交于 2019-12-13 14:59:11

问题


I'm trying to use a jaxb plugin to insert a interface into a choice element generating the classes from maven. 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:

<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:

<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]'!

Embedded error: unrecognized parameter -Xifins


回答1:


Unfortunately, it looks like the interface injection plugin is no longer well supported. In fact, I'm having trouble finding the JAR for download.

Thankfully, the JAXB2 Basics Plugins provides a similar mechanism for adding an interface to the generated JAXB stubs (see the Inheritance plugin).

The JAXB2 Basics plugin is available in the java.net Maven repository.

Using the Inheritance plugin, your POM will look like:

<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. 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>



回答2:


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).

Then, install the jar in the local repository:

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:

<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.



来源:https://stackoverflow.com/questions/1999163/how-to-use-jaxb-commons-plugins-from-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!