注:以下步驟均是在Tomcat 7.0下實現!Tomcat 6步驟略有不同,請自行查找。
1、在項目下pom.xml文件中的<plugins
>標籤內加入:
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.3-SNAPSHOT</version> <configuration> <url>http://localhost:8080/manager/text</url> <server>tomcat</server> </configuration> </plugin>
可在直接在這裏使用
<username>tomcat管理帳號</username>
<password>tomcat管理密碼</password>
而不使用<server>tomcat</server>
2、在maven的settings.xml中加入:
<repository> <id>people.apache.snapshots</id> <url>http://repository.apache.org/content/groups/snapshots-group/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> <pluginRepository> <id>apache.snapshots</id> <name>Apache Snapshots</name> <url>http://repository.apache.org/content/groups/snapshots-group/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository>
3、打開tomcat的安裝目錄的 conf/tomcat-users.xml,添加以下內容:
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="tomcat" password="123456" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
4、在maven的settings.xml中加入:
<server> <id>tomcat</id> <username>tomcat管理帳號</username> <password>tomcat管理密碼</password> </server>
這裏的<id>tomcat<id>的內容應與POM.xml中的<server>tomcat</server>的內容保持一致。若在POM.xml中直接使用帳號密碼,此步可以忽略。
5、使用在maven命令環境中輸入命令
既可以實現一條命令部署項目。