1.需要顯示指定打包爲war
< packaging>war</packaging>
2. maven 自帶的屬性
${project.groupId} ${project.version]
3. 使用jetty-maven-plugin對web項目進行測試
配置jetty 插件:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.1.0.RC1</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds> //指名掃描間隔時間
<webAppConfig>
<contextPath>/account</contextPath> //訪問的路徑
</webAppConfig>
</configuration>
</plugin
修改settings.xml
<pluginGroups>
<pluginGroup>org.moetbat.jetty</pluginGroup>
</pluginGroups>
然後在命令行運行:
mvn jetty:run
mvn jetty:run -Djetty.port=9999
使用Cargo實現自動化部署
cargo-maven2-plugin提供了Maven集成,
步驟:standalone 模式(複製保存) existing模式(指定配置目錄)
- <plugin>
- <groupId>org.codehaus.cargo</groupId>
- <artifactId>cargo-maven2-plugin</artifactId>
- <version>1.1.3</version>
- <configuration>
- <container>
- <containerId>tomcat7x</containerId>
- <home>E:\tomcat\apache-tomcat-7.0.26</home>
- </container>
- <configuration>
- <type>existing</type>
- <home>E:\tomcat\apache-tomcat-7.0.26</home>
- <properties>
- <cargo.servlet.port>8090</cargo.servlet.port>
- </properties>
- <!--
- <type>standalone</type>
- <home>${project.build.directory}/tomcat7x</home>
- -->
- </configuration>
- </configuration>
- </plugin>
在settings.xml中配置,可以使用命令 mvn cargo:start
當使用standalone 時,上述命令不起作用時,使用mvn cargo:run
注意:cargo:start需要額外配置一個<wait>的參數,否則的話雖然cargo:start可以把容器啓動,但是在maven生命週期跑完之後,容器也就立刻關閉了
這個需要自動啓動tomcat 否則不能訪問。
遠程配置:
- <plugin>
- <groupId>org.codehaus.cargo</groupId>
- <artifactId>cargo-maven2-plugin</artifactId>
- <version>1.1.3</version>
- <configuration>
- <container>
- <containerId>tomcat7x</containerId>
- <type>remote</type>
- </container>
- <configuration>
- <type>runtime</type>
- <properties>
- <cargo.remote.username>tomcat</cargo.remote.username>
- <cargo.remote.password>tomcat</cargo.remote.password>
- <cargo.remote.manager.url>http://localhost:8080/manager</cargo.remote.manager.url>
- </properties>
- </configuration>
- </configuration>
- </plugin>
使用命令:mvn cargo:redeploy
注意使用jps查看java進程