JAXB2 Maven插件-使用插曲-xsd的通用项目

JAXB2 Maven插件-使用插曲-xsd的通用项目,xsd,maven-jaxb2-plugin,Xsd,Maven Jaxb2 Plugin,我想要一个项目a,其中包含一些常用的XML模式文件和一些依赖于jaxb生成的类的java类,使用名称空间a和包a,我想要一个项目B依赖于项目a 在项目B中,我想使用项目a中的一些XML类型创建一个XML模式文件,项目B具有名称空间B,然后JAXB需要将模式B中的java类生成到包B中 我知道片段和目录可能会有所帮助,但我无法阻止jaxb在项目b中两次从模式a创建java类 以下是我的maven配置: 项目A: 项目B: b、 xsd 这样,您就不用使用这些片段了,因为您在B项目中解包了xsd,因

我想要一个项目a,其中包含一些常用的XML模式文件和一些依赖于jaxb生成的类的java类,使用名称空间a和包a,我想要一个项目B依赖于项目a

在项目B中,我想使用项目a中的一些XML类型创建一个XML模式文件,项目B具有名称空间B,然后JAXB需要将模式B中的java类生成到包B中

我知道片段和目录可能会有所帮助,但我无法阻止jaxb在项目b中两次从模式a创建java类

以下是我的maven配置:

项目A: 项目B: b、 xsd
这样,您就不用使用这些片段了,因为您在B项目中解包了xsd,因此可以从项目中重新生成类

您应该使用以下配置

    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.8.1</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <args>
                <arg>-Xannotate</arg>
                <arg>-Xnamespace-prefix</arg>
                <arg>-nv</arg>
            </args>
            <extension>true</extension>
            <forceRegenerate>true</forceRegenerate>
            <schemas>
                <schema>
                    <fileset>
                        <directory>${basedir}/src/main/resources/schema/project/b</directory>
                        <includes>
                            <include>*.xsd</include>
                        </includes>
                    </fileset>
                </schema>
                <schema>
                    <dependencyResource>
                        <groupId>com.project.a</groupId>
                        <artifactId>artifact.a</artifactId>
                        <resource>schema/a.xsd</resource>
                    </dependencyResource>
                </schema>
            </schemas>
            <episodes>
                <episode>
                    <groupId>com.project.a</groupId>
                    <artifactId>artifact.a</artifactId>
                </episode>
            </episodes>
            <debug>true</debug>
            <verbose>true</verbose>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics</artifactId>
                    <version>0.6.2</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics-annotate</artifactId>
                    <version>0.6.2</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-namespace-prefix</artifactId>
                    <version>1.1</version>
                </plugin>
            </plugins>
        </configuration>
    </plugin>

记住将项目A添加为依赖项。

您解决了这个问题吗?如果是,您是如何解决的
<!-- Used to pull XSD files from the JAR -->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>unpack-xsd-files</id>
        <phase>initialize</phase>
        <goals>
          <goal>unpack</goal>
        </goals>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>a</groupId>
              <artifactId>a-xsd</artifactId>
              <version>${project.version}</version>
              <type>jar</type>
            </artifactItem>
          </artifactItems>
          <includes>wsdl/*.xsd</includes>
          <outputDirectory>${project.basedir}/target/xsd-includes</outputDirectory>
        </configuration>
      </execution>
    </executions>
  </plugin>

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

      <episodes>
        <episode>
          <groupId>a</groupId>
          <artifactId>sca-xsd</artifactId>
          <version>${project.version}</version>
        </episode>
      </episodes>

      <episode>false</episode>

      <schemaIncludes>
            <include>wsdl/b.xsd</include>
      </schemaIncludes>
      <generatePackage>b</generatePackage>
    </configuration>
  </plugin>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema version="1" targetNamespace="a"
  xmlns:tns="a" xmlns:com="b"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:import namespace="a" schemaLocation="..relPathTo/target/xsd-includes/a.xsd>

  <xs:element name="addShipmentOrderResult">
    <xs:annotation>
  <xs:documentation>
    Result object for addShipmentOrder.
  </xs:documentation>
    </xs:annotation>
    <xs:complexType>
  <xs:complexContent>
    <xs:extension base="com:baseResult">

    </xs:extension>
  </xs:complexContent>
</xs:complexType>
  </xs:element>
</xs:schema>
    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <version>0.8.1</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <args>
                <arg>-Xannotate</arg>
                <arg>-Xnamespace-prefix</arg>
                <arg>-nv</arg>
            </args>
            <extension>true</extension>
            <forceRegenerate>true</forceRegenerate>
            <schemas>
                <schema>
                    <fileset>
                        <directory>${basedir}/src/main/resources/schema/project/b</directory>
                        <includes>
                            <include>*.xsd</include>
                        </includes>
                    </fileset>
                </schema>
                <schema>
                    <dependencyResource>
                        <groupId>com.project.a</groupId>
                        <artifactId>artifact.a</artifactId>
                        <resource>schema/a.xsd</resource>
                    </dependencyResource>
                </schema>
            </schemas>
            <episodes>
                <episode>
                    <groupId>com.project.a</groupId>
                    <artifactId>artifact.a</artifactId>
                </episode>
            </episodes>
            <debug>true</debug>
            <verbose>true</verbose>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics</artifactId>
                    <version>0.6.2</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-basics-annotate</artifactId>
                    <version>0.6.2</version>
                </plugin>
                <plugin>
                    <groupId>org.jvnet.jaxb2_commons</groupId>
                    <artifactId>jaxb2-namespace-prefix</artifactId>
                    <version>1.1</version>
                </plugin>
            </plugins>
        </configuration>
    </plugin>