Maven: The Complete Reference

10.6. Deploying Your Project Website

Once your project’s documentation has been written and you’ve creates a site to be proud of, you will want to deploy it to a server. To deploy your site you’ll use the Maven Site plugin which can take care of deploying your project’s site to a remote server using a number of methods including FTP, SCP, and DAV. To deploy the site using DAV, configure the site entry of the distributionManagement section in the POM, like this:

Configuring Site Deployment. 

<project>
    ...
    <distributionManagement>
        <site>
            <id>sample-project.website</id>
            <url>dav:https://dav.sample.com/sites/sample-project</url>
        </site>
    </distributionManagement>
    ...
</project>

The url in distribution management has a leading indicator dav which tells the Maven Site plugin to deploy the site to a URL that is able to understand WebDAV. Once you have added the distributionManagement section to our sample-project POM, we can try deploying the site:

$ mvn clean site-deploy

If you have a server configured properly that can understand WebDAV, Maven will deploy your project’s web site to the remote server. If you are deploying this project to a site and server visible to the public, you are going to want to configure your web server to access for credentials. If your web server asks for a username and password (or other credentials, you can configure this values in your ~/.m2/settings.xml).

10.6.1. Configuring Server Authentication

To configure a username/password combination for use during the site deployment, we’ll include the following in $HOME/.m2/settings.xml:

Storing Server Authentication in User-specific Settings. 

<settings>
    ...
    <servers>
        <server>
            <id>sample-project.website</id>
            <username>jdcasey</username>
            <password>b@dp@ssw0rd</password>
        </server>
        ...
    </servers>
    ...
</settings>

The server authentication section can contain a number of authentication elements. In the event you’re using SCP for deployment, you may wish to use public-key authentication. To do this, specify the publicKey and+ passphrase+ elements, instead of the password element. You may still want to configure the username element, depending on your server’s configuration.

10.6.2. Configuring File and Directory Modes

If you are working in a large group of developers, you’ll want to make sure that your web site’s files end up with the proper user and group permissions after they are published to the remote server. To configure specific file and directory modes for use during the site deployment, include the following in $HOME/.m2/settings.xml:

Configuring File and Directory Modes on Remote Servers. 

<settings>
    ...
    <servers>
        ...
        <server>
            <id>hello-world.website</id>
            ...
            <directoryPermissions>0775</directoryPermissions>
            <filePermissions>0664</filePermissions>
        </server>
    </servers>
    ...
</settings>

The above settings will make any directories readable and writable by either the owner or members of the owner’s primary group; the anonymous users will only have access to read and list the directory. Similarly, the owner or members of the owner’s primary group will have access to read and write any files, with the rest of the world restricted to read-only access.