How to deploy site with “mvn site-deploy” – WebDAV example

Here’s a guide to show you how to use “mvn site:deploy” to deploy your generated documentation site to server automatically, via WebDAV mechanism.

P.S In this article, we are using Apache server 2.x with WebDAV enabled.

1. Enabled WebDAV

See this guide to learn how to enable WebDAV access on Apache server 2.x.

2. Configure Where to Deploy

In pom.xml, configure where to deploy your site within “distributionManagement” tag.


<distributionManagement>
    <site>
      <id>mkyongserver</id>
      <url>dav:http://127.0.0.1/sites/</url>
    </site>
</distributionManagement>
Note
The “dav” prefix is added before the HTTP protocol, it means deploy your site via WebDAV mechanism. Alternately, you can replace it with “scp” if your server is supported “scp” access.

Tell Maven to use “wagon-webdav-jackrabbit” extension for deployment.


<build>
	<extensions>
		<extension>
			<groupId>org.apache.maven.wagon</groupId>
			<artifactId>wagon-webdav-jackrabbit</artifactId>
			<version>1.0-beta-7</version>
		</extension>
	</extensions>
</build>
wagon-webdav
Some claimed to use “wagon-webdav“, but this is not working for me, so, use “wagon-webdav-jackrabbit” instead.


<extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-webdav</artifactId>
            <version>1.0-beta-2</version>
</extension>

See a full pom.xml file.


<project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mkyong.core</groupId>
  <artifactId>mkyong-core</artifactId>
  <packaging>jar</packaging>
  <version>1</version>
  <name>mkyong-core</name>
  <url>http://maven.apache.org</url>
  <build>
	<extensions>
		<extension>
			<groupId>org.apache.maven.wagon</groupId>
			<artifactId>wagon-webdav-jackrabbit</artifactId>
			<version>1.0-beta-7</version>
		</extension>
	</extensions>
  </build>
  <distributionManagement>
    <site>
      <id>mkyongserver</id>
      <url>dav:http://127.0.0.1/sites/</url>
    </site>
  </distributionManagement>
</project>

3. Configure WebDAV Authentication

Normally, WebDAV is required authentication access. So, you need to put the related authentication detail (username and password) in %MAVEN_PATH%/conf/settings.xml.

File : settings.xml


<servers>
	<server>
		<id>mkyongserver</id>
		<username>USERNAME</username>
		<password>PASSWORD</password>
	</server>
</servers>
What is “mkyongserver” id ?
The server id in Maven’s “settings.xml” file will be referenced by the site id in “pom.xml” file.

4. mvn site:deploy

Issue “mvn site:deploy” :


D:\workspace-new\mkyong-core>mvn site:deploy
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'site'.
[INFO] ------------------------------------------------------------------------
[INFO] Building mkyong-core
[INFO]    task-segment: [site:deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [site:deploy {execution: default-cli}]
http://127.0.0.1/sites/ - Session: Opened
//......
#http://127.0.0.1/sites//./css/maven-base.css - Status code: 201
Transfer finished. 4594 bytes copied in 0.044 seconds
18 April 2011 4:23:40 PM org.apache.commons.httpclient.auth.AuthChallengeProcessor 
selectAuthScheme
INFO: digest authentication scheme selected
Uploading: ./css/maven-theme.css to http://127.0.0.1/sites/
//......
Transfer finished. 10120 bytes copied in 0.142 seconds
http://127.0.0.1/sites/ - Session: Disconnecting
http://127.0.0.1/sites/ - Session: Disconnected
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5 seconds
[INFO] Finished at: Mon Apr 18 16:23:43 SGT 2011
[INFO] Final Memory: 9M/16M
[INFO] ------------------------------------------------------------------------
D:\workspace-new\mkyong-core>

All your sites folders and files, under project folder – “target/site” will be deployed to server automatically.

5. Output

In this case, you can access the deployed site via this URL : http://127.0.0.1/sites/, see following figure :

auto deploy site with Maven

Done.

References

  1. http://maven.apache.org/plugins/maven-site-plugin/usage.html
  2. http://mojo.codehaus.org/wagon-maven-plugin/usage.html
  3. http://maven.apache.org/plugins/maven-site-plugin/deploy-mojo.html
  4. http://maven.40175.n5.nabble.com/site-deploy-using-DAV-with-digest-auth-td125042.html
  5. http://www.sonatype.com/books/maven-book/reference/site-generation-sect-deploy-site.html
  6. http://www.mkyong.com/apache/how-to-enable-webdav-in-apache-server-2-2-x-windows/

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
trackback
Maven: Site generation e reportistica, generare il sito web di un progetto con Maven e i report per analizzare il codice | Cose Non Javiste

[…] How To Deploy Site With “Mvn Site-Deploy” – WebDAV Example […]

trackback
Maven + WebDAV – Embedded error: Failed to transfer file: … Return code is: 405

[…] mvn site:deploy + WebDAV example This article is under – Maven Tutorials , Tags : error maven webdav mkyong Founder and Chief Editor of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. […]

TestConfig
Guest
TestConfig

I was getting a 401, 403 error while uploading the war file to Apache server.
Following worked me
1. Edit httpd.conf add following
require user admin

2. If you have not changed your local repo then move your settings.xml file from maven installation (mine was d:\maven\conf\settings.xml ) to .m2/settings.xml

Hope this helps :)

TestConfig
Guest
TestConfig

Sorry I missed this XML

1. Edit httpd.conf add following
require user admin

 <LimitExcept GET OPTIONS PUT>
        require user admin
    </LimitExcept> 
trackback
Maven Tutorials

[…] How to deploy site with “mvn site-deploy” – WebDAV example “mvn site-deploy” to deploy generated documentation site to server automatically, via WebDAV. […]