Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

maven-2

war

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?

like image 942
TraderJoeChicago Avatar asked Sep 04 '10 15:09

TraderJoeChicago


2 Answers

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.

like image 148
Jcs Avatar answered Oct 25 '22 09:10

Jcs


If you want the source files in the same directory as the class files you would use:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <resource>
                        <directory>${build.sourceDirectory}</directory>
                        <targetPath>WEB-INF/classes</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
like image 33
Will Avatar answered Oct 25 '22 09:10

Will