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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<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