Maven: Retrieve Code, Compile, Deploy

本文介绍了一种使用Maven进行自动化部署的方法,包括配置pom.xml以实现项目的编译、从SVN获取最新代码及通过批处理命令完成整个部署过程。文章详细展示了如何设置tomcat-maven-plugin和maven-scm-plugin,以及所需的settings.xml和tomcat-users.xml配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[b]1, Compile, Deploy[/b]
1) pom.xml

<project>
...
</build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://127.0.0.1:8080/manager</url>
<server>mytomcat</server>
</configuration>
</plugin>
</plugins>
</build>
</project>


2) settings.xml in \Users\[account]\.m2\ of Operation System

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers>
<server>
<id>mytomcat</id>
<username>test</username>
<password>pass</password>
</server>
</servers>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>



3) tomcat-users.xml

<role rolename="manager"/>
<role rolename="admin"/>
<user username="test" password="pass" roles="manager"/>


2, Get latest code from SVN
1) pom.xml

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.3</version>
<configuration>
<goals>install</goals>
<username>***</username>
<password>***</password>
</configuration>
</plugin>



...
<scm>
<connection>scm:svn:file://192.168.1.***//repository/***/</connection>
<developerConnection>scm:svn:file://192.168.1.***//repository/***//</developerConnection>
<url>scm:svn:file://192.168.1.180/repository/***//</url>
</scm>
</project>


3, install software with svn command. i.e. Slik-Subversion-1.6.12-win32.msi

svn --username *** --password *** --non-interactive update F:\***

svn help update

http://www.sliksvn.com/en/download



4, batch DOS command

Echo ------Start To Deploy Project------
Echo ------
Echo ------Start To Retrieve Latest Content From SVN------
call mvn scm:update
Echo ------
Echo ------Start To Install Application------
call mvn install
Echo ------
Echo ------Start To Deploy Application On Tomcat------
call mvn tomcat:redeploy
Echo ------
Echo ------Deploy Done------



[b]Note:[/b]
1, SCM URL

scm:svn:svn://[username[:password]@]server_name[:port]/path_to_repository
scm:svn:svn+ssh://[username@]server_name[:port]/path_to_repository
scm:svn:file://[hostname]/path_to_repository
scm:svn:http://[username[:password]@]server_name[:port]/path_to_repository
scm:svn:https://[username[:password]@]server_name[:port]/path_to_repository


2, SCM example

scm:svn:file:///svn/root/module
scm:svn:file://localhost/path_to_repository
scm:svn:file://my_server/path_to_repository
scm:svn:http://svn.apache.org/svn/root/module
scm:svn:https://username@svn.apache.org/svn/root/module
scm:svn:https://username:password@svn.apache.org/svn/root/module


3, SCM Command


mvn scm:changelog
mvn -DstartDate=YYYY-MM-DD -DendDate=YYYY-MM-DD scm:changelog

mvn scm:diff
mvn -DstartRevision=<revision> -DendRevision=<revision> scm:diff

mvn scm:validate
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值