Maven - 将 XSD 作为依赖项

too*_*kit 5 xsd maven-2

我们有一个项目定义了它使用 XSD 文件生成的消息格式。

将这些 XSD 文件作为另一个项目的依赖项的最简单方法是什么?

我正在考虑使用maven-build-helper Attach-artifact目标来附加我的 XSD 文件。

有没有更好的机制?

小智 5

我不知道附加工件的目标,但我做了像你要求的那样。我有 wsdl 和 xsd 文件来使用 axis2 编写 Web 服务工件及其客户端工件。

  1. 我将 wsdl 和 xsd 放在一个名为“wsdl”的自己的项目中,放在 src/main/resources/META-INF 中,仅此而已。
  2. 我为生成的 Java-SOAP 代码创建了一个名为“soap”的自己的项目。在这个项目中,我添加了 wsdl 项目作为依赖项,并在初始化阶段通过 maven-dependency-plugin 将 wsdl 和 xsd 文件解压到目标文件夹。所以我可以用它来生成 SOAP 代码。
  3. 我将soap 项目用作Webservice 项目和客户端项目的依赖项。

我将所有这些项目放入一个多模块项目中,以便我可以一起构建。我认为对您来说重要的部分是依赖插件的配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>unpack-wsdl-dependency</id>
        <phase>initialize</phase>
        <goals>
          <goal>unpack</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <artifactItems>
        <artifactItem>
          <groupId>${groupId}</groupId>
          <artifactId>wsdl</artifactId>
          <outputDirectory>target/wsdl</outputDirectory>
          <includes>META-INF/*.wsdl,META-INF/*.xsd</includes>
        </artifactItem>
      </artifactItems>
      <!-- other configurations here -->
    </configuration>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

希望有帮助。

问候迈克尔