Maven Assemblies

Due to requests I received for source code for my open source file parser project (http://www.javaforge.com/project/2066), I had to quickly figure out a way to package a zip file that would contain

- source code
- binary jar file
- javadocs
- license and release-changes text files.

Since I am using Maven, I found that assemblies can come to my help. Thought I'd jot down a few things here so that others can google to it and find the same.

I created a file src/main/assemply/src.xml. This contained a list of artifacts I wanted to package as a zip. The XML should be self-explanatory.
 
<assembly>
    <id>dist</id>
    <formats>
        <format>zip</format>
    </formats>
    <baseDirectory>flatfilereader</baseDirectory>
    <includeBaseDirectory>true</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>target</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>docs</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>*.doc</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>target/site</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>**/*</include>
            </includes>
        </fileSet>
        <fileSet>
            <directory>src/main/resources</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>license.txt</include>
                <include>release-changes.txt</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>


In my pom.xml I have the following under the build section.
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <configuration>
                    <outputDirectory>target</outputDirectory>
                    <finalName></finalName>
                    <attach>false</attach>
                </configuration>
                <executions>
                    <execution>
                        <id>make-source-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <outputDirectory>target</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>make-javadoc</id>
                        <phase>package</phase>
                        <goals>
                            <goal>javadoc</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>
                            src/main/assembly/src.xml
                        </descriptor>
                    </descriptors>
                </configuration>
            </plugin>
        </plugins>
    </build>


Once this is done, running command "mvn assembly:assembly" will trigger the build and the creation of my distributable file as target\flatfilereader-0.6-dist.zip




 del.icio.us  Stumbleupon  Technorati  Digg 

 

What did you think of this article?




Trackbacks
  • Trackbacks are closed for this entry.
Comments
  • No comments exist for this entry.
Leave a comment

Submitted comments will be subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.