March 5, 2009

Create a Maven project site in NetBeans

Within a Maven project it is easy to create a project site. We need to create the src/site directory and place a site.xml file in it. Here is a very simple and basic site.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="app"/>

And of course we can add content files for the project site. To generate the site we only have to run mvn site. And if we use NetBeans we can generate the site with a mouse click.

In our Maven project we have a Project site node. If we right-click on the node we get the following pop-up menu:

We notice the options Generate Site and Deploy Site. If we select Generate Site we get a dialog window with the Maven command that is about to run:

We could change some fields here, but most of the time we just press the OK button. And the project site is generated. The generated site is placed in the target/site directory. If we look at the output window and see the Maven output we notice a link View Generated Project Site:

We can click on this link and NetBeans will open the site's index.html file in a web browser.

We can also deploy the project site to a web server with the Deploy Site option from the pop-up menu. This command is executed immediately by NetBeans and the if the configuration in our pom.xml is correct, the site is deploy to a web server.