Maven - Have an XSD as a dependency

心已入冬 提交于 2019-12-23 12:28:04

问题


We have one project that defines the message formats it produces with XSD files.

What is the easiest way to make these XSD files as dependencies of another project?

I was looking at using the maven-build-helper attach-artifact goal to attach my XSD files.

Is there a better mechanism?


回答1:


I don't know the attach-artifact goal but I did something like you asked for. I had wsdl and xsd files to write Webservice artifacts and its client artifacts with axis2.

  1. I put my wsdl and xsd in an own project named 'wsdl' to src/main/resources/META-INF and nothing else.
  2. I made a own project named 'soap' for the generated Java-SOAP-Code. In this project I added the the wsdl project as dependency and unpacked the wsdl and xsd files via maven-dependency-plugin to the target folder in the initialize-phase. So I can use it to generate the SOAP-Code.
  3. The soap project I used as dependency for the Webservice project and for the client project.

I put all these projects to a multi module project so that I can build all together. I think the important part for you is the configuration of dependency-plugin:

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

Hope that helps.

Greetings Michael



来源:https://stackoverflow.com/questions/4389702/maven-have-an-xsd-as-a-dependency

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