Withheld
Withheld

Reputation: 4703

How to add WSDL, XSD (and possibly other files) to WAR

I have a very simple pom.xml that generates a fully working web service if deployed locally (Tomcat 7). This is its <build> section:

  <build>
    <finalName>${artifact.id}</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>2.3.1</version>
        <executions>
          <execution>
            <id>generate-sources</id>
            <configuration>
              <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
              <wsdlOptions>
                <wsdlOption>
                  <wsdl>${basedir}/src/main/wsdl/mywebservice.wsdl</wsdl>
                  <extraargs>
                    <extraarg>-impl</extraarg>
                    <extraarg>-verbose</extraarg>
                  </extraargs>
                  <wsdlLocation>${basedir}/src/main/wsdl/mywebservice.wsdl</wsdlLocation>
                </wsdlOption>
              </wsdlOptions>
            </configuration>
            <goals>
              <goal>wsdl2java</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${basedir}/target/generated/src/main/java</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <id>attach-artifacts</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${basedir}/src/main/wsdl/mywebservice.wsdl</file>
                  <type>wsdl</type>
                </artifact>
                <artifact>
                  <file>${basedir}/src/main/xsd/myschema.xsd</file>
                  <type>xsd</type>
                </artifact>
              </artifacts>
            </configuration>
          </execution>

        </executions>
      </plugin>

    </plugins>
  </build>

The reason it only works if deployed locally and not when deployed to a remote server is because the remote server cannot find the .wsdl and the .xsd files in development source directories ${basedir}/target/generated/src/main/ and they are also nowhere to be found in the WAR file.

Apparently, I am missing something in my pom.xml that would make Maven add or attach those files to the WAR.

I tried the attach-artifact goal (as quoted above) but it only copies the files to my local (development) .m2 repository, not to the WAR file.

How do I add or attach files to the actual .war file to be deployed?

Upvotes: 4

Views: 9044

Answers (1)

Withheld
Withheld

Reputation: 4703

I solved the mystery.

Posting the answer here in case another newbie to Maven (plus CXF?) encounters this problem:

It turns out that the attach-artifact execution is totally unneeded and is a shot in the wrong direction.

All I had to do was to add at the top of the <build> section, just before <plugins> the following:

<resources>
    <resource>
        <directory>src/main/wsdl</directory>
    </resource>
    <resource>
        <directory>src/main/xsd</directory>
    </resource>
</resources>

That's all. Maven then automagically places all files in those directories in WEB-INF/classes/.

Upvotes: 7

Related Questions