Most of us use Maven for building our projects and preparing a JAR or a WAR or an EAR to be deployed on server. However, during the development life-cycle we do not realize that Maven can be used for a much higher purpose – “Create a project site to show all of projects’ information”. For many years, that I have been using Maven myself, this is something that I never thought off using to my advantage – I guess I never wanted to do something like that.
Last week, when I launched my project as an Open Source Library, I realized that I need a easy and quick way to make many artifacts available for my project. I have used Google for code hosting and issue tracking, however there are other documents like JavaDocs, list of dependencies, XRef Source that provide a lot of additional information which would be useful to whom so ever decides to use the library.
Necessity if the mother of invention
In my case, it was not an invention, but it sure was a learning experience as I started exploring maven-site-plugin. This plugin generates various reports for a maven project including those that have been configured in the pom.xml file. However, it was not a straight forward implementation because I had some additional requirements like placing Google Analytics Code and placing custom Project information on my site. In this post, I will make an attempt to explain some of the things I did to help me generate my site.
To understand what I did, you should have a quick look at the site that I have deployed. I will now start take one section at a time and explain what changes I made to my pom for that section to work. I have also attached the pom file with this post for you quick reference.
The image on the right explains the main sections of the POM.XML. This section will configure the Project Information and Project Team pages. I have added only a few details that i needed, but you can add a lot more information as you need.
The next section holds the License information. I am using the Apache License 2.0 and hence I am providing the URL for the license from Apache. This section generates the Project License page for site. The next two sections define the Project Repository and Issue Management (Defect Management) settings.
Rest everything is standard POM stuff i.e. dependencies and Build plugins to run test cases etc. I am not going to take a deep dive into those because there are just so many tutorials on the same. However, what is important are the sections on Java Cods and Source Code Reference. To generate these two sections as a part of the Maven Site, you need to configure the Reporting Plugins as follows:
<reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <links> <link>http://download.oracle.com/javase/6/docs/api/</link> </links> <!--DVFMTSC--> </configuration> <version>2.8</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jxr-plugin</artifactId> <version>2.3</version> </plugin> </plugins> </reporting>
And lastly, to setup the left-navigation menu, you need to add a site.xml file into the “src\site” folder of your project and provide the menu details and their linking to the pages.
In this file you can also add code for Google Analytics, you will notice in the image below that I have added the Google Analytic code to the header section which then copies the code over to each of the static HTML pages and allows me to track the same.
I hope you find this useful and are able to use it to publish your own site too.