Get the most out of Maven 2 site generation

Steps for creating a Maven-based Website

1 2 Page 2
Page 2 of 2

Another more development-oriented option is to use your SCM repository to track changes. The changelog plug-in generates a nice report describing which files have been changed and by whom:

 <reporting>
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>changelog-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </reporting>

Finally, if you use @todo tags to remind you of things to be done (which is a good coding practice), the taglist report will generate a list of all the items marked @todo or TODO:

 <reporting>
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>taglist-maven-plugin</artifactId>
      </plugin>
    <plugins>
  </reporting>

Add specific site content

You can also add your own original content to your site. You can put FAQ pages, technical documentation, or whatever takes your fancy.

Site content is stored in the src/site directory and organized in three main directories, as shown in this example:

 - src/
   + site/
      + apt/
      |  + vision-statement.apt
      |     ...
      |
      + fml/
      |  + faq.fml
      |     ...
      |
      + xdoc/
      |  + best-practices.xml
      |     ...
      |
      + site.xml

To define site layout and navigation, you must write a site descriptor (placed in the site.xml file). This file basically describes the banners and menus to appear on your site. In our simple example, this file takes the following form:

 

<?xml version="1.0" encoding="ISO-8859-1"?> <site> <bannerLeft> <name>Hotel Database</name> <src>http://maven.apache.org/images/apache-maven-project.png</src> <href>http://maven.apache.org/</href> </bannerLeft> <bannerRight> <src>http://maven.apache.org/images/maven-small.gif</src> </bannerRight> <body> <links> <item name="Maven" href="http://maven.apache.org/"/> <item name="Apache" href="http://www.apache.org/"/> </links>

<menu name="The Hotel Database project> <item name="Vision Statement" href="/vision-statement.html"/> <item name="Best Practices" href="/best-practices.html"/> <item name="FAQs" href="/faqs.html"/> </menu>

${reports}

</body> </site>

Supported file formats

Site content can be added in a variety of formats. The traditional Maven documentation format is XDoc, a loosely structured general-purpose XML format for site content. XDoc files are stored in the xdoc directory. XDoc resembles XHTML and will prove familiar to anyone knowing HTML. A simple example is shown here:

 

<document> <properties> <author email="user@company.com> The Wakaleo Team< /author> <title> The Hotel Database Vision Statement< /title> </properties> <body>

<section name="Introduction"> <p> This application demonstrates Maven 2 site generation functionalities. One of the nicer features of Maven is the ability to create an internal technical web site at very little cost. Maven 2 extends this functionality, and gives you powerful new ways to generate site content... </p>

<subsection name="Team Communication">

<! --Team communication is an essential part of any project. And wasting time looking for technical project information can be costly and frustrating. Clearly, any IT project will benefit from having its own dedicated technical web site. Some useful things it provides are: <ul> <li>Online javadoc</li> <li>Quality assurance</li> <ul> <li>Static code audits with Checkstyle or PMD

Maven 2 introduces a new format, the APT (almost plain text) format, designed to be more convenient for writing technical site content. The APT format is a wiki-like text format handy for writing simple structured documents and for using simple text formatting and indentation rules. The APT files (*.apt) go in the apt directory. A full description of the APT format can be found in Resources. A simple example is shown here:

 

----- The Hotel Database Vision Statement ----- The Wakaleo Team ----- January 2006 Introduction

One of the nicer features of Maven is the ability to create an internal technical web site at very little cost. Maven 2 extends this functionality, and gives you powerful new ways to generate site content...

* Sub-section title

Team communication is an essential part of any project. And wasting time looking for technical project information can be costly and frustrating. Clearly, any IT project will benifit from having its own dedicated technical web site... * Item 1 * Item 2 * Item 2.1 * Item 2.2

Both documents generate a page similar to the one shown in Figure 4.

Figure 4. Some site content

The fml directory is for FAQ pages, which are written using the FML format. The FML format is an XML format designed specifically for FAQ pages. A simple example is shown here:

 

<?xml version="1.0"?> <faqs title="About the Hotel Database application">

<part id="about"> <faq> <question> This is a very frequent question</question> <answer> <p> Thank you for asking that question, here is the answer... </p> </answer> </faq>

<faq> <question> Here is another question?< /question> <answer> <p> This is the answer to this question... </p> </answer> </faq> </part> </faqs>

This would generate the page shown in Figure 5.

Figure 5. An example of a simple FAQ page

Other formats, such as DocBook, are also in development at the time of this writing.

Deploying your site

To deploy your site, you will first have to tell Maven where to deploy it by defining the location in the pom.xml file, as follows:

 <distributionManagement> 
  <site> 
    <id> website</id> 
    <url> scp://www.mycompany.com/www/docs/project/</url> 
  </site> 
</distributionManagement> 

Now you can deploy your site. Run mvn site-deploy.

The site will be copied, using scp (the only method currently accepted), to the destination server for all to see.

Site generation and continuous integration

How often should you update your site? This is often a matter of personal and team preference. Don't forget that site generation is a processor-intensive process. A really big project on a busy server may take 10 or 15 minutes to generate. So if you run site generation every 5 minutes, your system administrator will probably get annoyed (I've seen servers go down like this). Often, once or twice a day is enough.

Conclusion

In this article, we have walked through the basics of setting up a Maven 2 Website. Maven 2 site generation is powerful and flexible, providing many useful standard technical reports out of the box; much can be done with relatively little initial effort. In addition to the traditional XDoc and FML formats, the APT format provides a new, convenient way of writing specific technical content. Site generation is also much faster in Maven 2. Overall, although some reports are still in development, the site generation functionalities of Maven 2 are well worth investigating.

John Ferguson Smart has been involved in the IT industry since 1991 and in J2EE development since 1999. His specialties are J2EE architecture and development, and IT project management, including offshore project management. He has wide experience in open source Java technologies. He has worked on many large-scale J2EE projects involving international and offshore teams for government and businesses in both hemispheres, and also writes technical articles in the J2EE field. His technical blog can be found at http://www.jroller.com/page/wakaleo.

Learn more about this topic

1 2 Page 2
Page 2 of 2