如何使用 Maven 中的 jaxb_commons 插件

发布于 2024-08-16 21:54:15 字数 1846 浏览 9 评论 0 原文

我正在尝试使用 jaxb 插件将接口插入到从 Maven 生成类的选择元素中。问题是我似乎无法弄清楚如何从 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>

我在根 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>

运行给出:

设置 CmdLine 选项 '[-Xifins, -episode, /home/administrador/JavaApp/wnfe3/wnfe-ejb/target/ generated-sources/xjc/META-INF/sun-jaxb.episode]'!

嵌入错误:无法识别的参数-Xifins

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一袭白衣梦中忆 2024-08-23 21:54:15

不幸的是,接口注入插件似乎不再得到很好的支持。事实上,我无法找到可供下载的 JAR。

值得庆幸的是,JAXB2 基础插件提供了类似的机制,用于将接口添加到生成的 JAXB 存根(请参阅继承插件)。

JAXB2 Basics 插件可在 java.net Maven 存储库中找到。

使用 Inheritance 插件,您的 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>

Inheritance 插件文档 有一个JAXB 绑定的示例。为了您的方便,我复制了下面的示例:

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

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>
枉心 2024-08-23 21:54:15

我真的不确定这是解决这个问题的“正确”方法,但这就是我所做的。首先,从 xjc-if-ins.jar .jar" rel="nofollow noreferrer">https://jaxb2-commons.dev.java.net/interface-insertion/xjc-if-ins.jar (找不到包含 的 jar java.net maven 存储库中的 IfInsertPluginImpl.class)。

然后,将 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

最后,将 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>

正如我所说,这可能不是最干净的配置方式jaxb2 插件使用接口插入插件,但是通过此设置,generate 目标不会抱怨 -Xifins 扩展。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文