这是一个指南,向您展示如何使用“ mvn site:deploy
”通过WebDAV机制将生成的文档站点自动部署到服务器。
PS在本文中,我们将使用启用了WebDAV的Apache服务器2.x。
1.启用的WebDAV
请参阅本指南,以了解如何在Apache服务器2.x上启用WebDAV访问 。
2.配置部署位置
在pom.xml
,在“ distributionManagement ”标记中配置将站点部署到何处。
<distributionManagement>
<site>
<id>mkyongserver</id>
<url>dav:http://127.0.0.1/sites/</url>
</site>
</distributionManagement>
注意
在HTTP协议之前添加了“ dav ”前缀,这意味着通过WebDAV机制部署您的站点。 或者,你可以,如果你的服务器支持“SCP”访问与“SCP”代替。
告诉Maven使用“ wagon-webdav-jackrabbit
”扩展进行部署。
<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
”,但这对我不起作用,因此,请改用“ wagon-webdav-jackrabbit
”。
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
<version>1.0-beta-2</version>
</extension>
查看完整的pom.xml文件。
<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.配置WebDAV身份验证
通常, WebDAV是必需的身份验证访问权限。 因此,您需要在%MAVEN_PATH%/conf/settings.xml
放入相关的身份验证详细信息(用户名和密码)。
文件:settings.xml
<servers>
<server>
<id>mkyongserver</id>
<username>USERNAME</username>
<password>PASSWORD</password>
</server>
</servers>
什么是“ mkyongserver” ID?
Maven的“settings.xml
”文件中的服务器ID将由“pom.xml
”文件中的站点ID引用。
4. mvn网站:部署
发出“ 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>
项目文件夹–“ 目标/站点 ”下的所有站点文件夹和文件将自动部署到服务器。
5.输出
在这种情况下,您可以通过以下URL访问已部署的站点: http://127.0.0.1/sites/
: http://127.0.0.1/sites/
,请参见下图:
做完了
参考文献
- http://maven.apache.org/plugins/maven-site-plugin/usage.html
- http://mojo.codehaus.org/wagon-maven-plugin/usage.html
- http://maven.apache.org/plugins/maven-site-plugin/deploy-mojo.html
- http://maven.40175.n5.nabble.com/site-deploy-using-DAV-with-digest-auth-td125042.html
- http://www.sonatype.com/books/maven-book/reference/site-generation-sect-deploy-site.html
- http://www.mkyong.com/apache/how-to-enable-webdav-in-apache-server-2-2-x-windows/
翻译自: https://mkyong.com/maven/how-to-deploy-site-with-mvn-site-deploy-webdav-example/