Wednesday, October 14, 2009

Include LICENSE and NOTICE in Your War or Jar File Automatically

Part of Apache 2.0 policy is to include the LICENSE and NOTICE files in any distribution.

If you would like to include these two files in your jar or war, and are using Maven 2 to build your project, then just use the tools-maven-plugin in your pom.xml:

1. Create a LICENSE and NOTICE file at the root of your project in the same directory as the pom.xml.

2. Add the plugin:

  ...
  <build>
    <plugins>
      ...
      <plugin>
         <groupId>org.apache.geronimo.genesis.plugins</groupId>
         <artifactId>tools-maven-plugin</artifactId>
         <executions>
             <execution>
                 <id>install-legal-files</id>
                 <phase>generate-resources</phase>
                 <goals>
                     <goal>copy-legal-files</goal>
                 </goals>
             </execution>
         </executions>
     </plugin>
     ...
    </plugins>
  </build>
  ...
3. You might want to also specify the version:
  ...
  <build>
     <pluginManagement>
         <plugins>
             ...
             <plugin>
                 <groupId>org.apache.geronimo.genesis.plugins</groupId>
                 <artifactId>tools-maven-plugin</artifactId>
                 <version>1.3.1</version>
             </plugin>
             ...
         </plugins>
     </pluginManagement>
     ...
  </build>
  ...

There is also a verify-legal-files goal, but it appears to look in the wrong place for the files in v1.3.1.

Note: if you are distributing a source and/or binary version of your project instead of just the war or jar (i.e. using zip, gz, tar, tar.gz, tar.bz2), you might want to use the maven-assembly-plugin to do this.

1 comment:

Gary S. Weaver said...

See also this thread where it was discussed in more detail...