How to generate a WAR with the source code in Maven?

TraderJoeChicago picture TraderJoeChicago · Sep 4, 2010 · Viewed 13.1k times · Source

I want to distribute the war of my web application generated with Maven with the source code inside it. How to do that with Maven?

Answer

Jcs picture Jcs · Sep 4, 2010

It is possible configure the maven-war-plugin to include the source directory as it was a web resource:

 <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <webResources>
            <resource>
              <directory>${build.sourceDirectory}</directory>
              <targetPath>sources</targetPath>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>

The java sources will be included in a sources directory in the war. Of course you should adapt the resource directory to your own maven layout.