你可以试试这个:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<url>${server-url}</url>
<path>${deploy-path}</path>
<username>${deploy-un}</username>
<password>${deploy-pw}</password>
</configuration>
</plugin>
当您的项目中有许多模块时,请在每个模块中使用<profile>
以将每个模块部署到不同的URLs
. 前任:
在模块 A 中:
<profile>
<id>server1</id>
<properties>
<!-- Replace with URL and authentication if needed -->
<server-url>http://localhost:8080/manager/text</server-url>
<deploy-path>/moduleA</deploy-path>
<deploy-un>tomcatscript</deploy-un>
<deploy-pw>p@ssw0rd</deploy-pw>
</properties>
</profile>
在模块 B 中:
<profile>
<id>server1</id>
<properties>
<!-- Replace with URL and authentication if needed -->
<server-url>http://localhost:8080/manager/text</server-url>
<deploy-path>/moduleB</deploy-path>
<deploy-un>tomcatscript</deploy-un>
<deploy-pw>p@ssw0rd</deploy-pw>
</properties>
</profile>
不要忘记将其添加到您的tomcat/conf/tomcat-users.xml
:
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<user username="tomcatscript" password="p@ssw0rd" roles="manager-script, manager-jmx"/>
然后在终端,使用这个:mvn tomcat7:[re]deploy -Pserver1
moduleA
将部署到http://localhost:8080/moduleA
,
moduleB
将部署到http://localhost:8080/moduleB
希望这可以帮助!