【问题标题】:JAXB 2 Maven plugin - use of episode - general project for xsdJAXB 2 Maven 插件 - 情节的使用 - xsd 的通用项目
【发布时间】:2013-11-29 16:16:33
【问题描述】:

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

在项目 B 中,我想要一个使用项目 A 中的一些 XML 类型的 XML 模式文件,项目 b 有命名空间 b,然后 JAXB 需要从模式 b 生成 java 类到包 b 中。

我知道剧集和目录可能会有所帮助,但我无法阻止 jaxb 在项目 b 中创建两次来自模式 a 的 java 类。

这是我的 Maven 配置:

项目 A:

<build>
<plugins>
  <plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <configuration>
      <schemaIncludes>
        <include>wsdl/WebServiceBaseRequestResponse.xsd</include>
      </schemaIncludes>
      <generatePackage>a</generatePackage>
      <episode>true</episode>
    </configuration>
  </plugin>

</plugins>
  </build>

项目 B:

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

b.xsd

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

【问题讨论】:

  • 你解决了这个问题吗?如果是,您是如何解决的? ——

标签: xsd maven-jaxb2-plugin


【解决方案1】:

通过这种方式,您不使用情节,因为您在 B 项目中解压缩 xsd,因此从 A 项目重新生成类。

你应该使用以下配置

    <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添加为依赖项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    • 1970-01-01
    • 2015-06-08
    • 2015-11-15
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    相关资源
    最近更新 更多