<servers>
<server>
<id>tomcat6</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
2.法1: 在pom中配置
<build>
<finalName>testdemo</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<server>tomcat6</server>
<url>http://localhost:8080/manager</url>
<path>/testdemo</path>
<!-- <warFile>${project.build.directory}/testdemo.war</warFile> -->
</configuration>
</plugin>
</plugins>
</build>
在命令行中输入如下命令:
a.切换的项目坐在文件夹
d:
cd workspace/testdemo
b.清理、打包
mvn clean (只执行mvn clean则target下不会生成war包)
或
mvn clean install -Dmaven.test.skip=true
c.继续输入命令
mvn tomcat:run (这个定位到工程的src/main/webapp目录)
或
mvn tomcat:run-war
在这里将启动tomcat
d.访问http://localhost:8080/testdemoe.停止tomcat
ctrl+c
y
===================================================================================
1.在~/.m2/settings.xml中增加如下的Tomcat服务器配置
<servers>
<server>
<id>tomcat6</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
2.法1: 在pom中配置
<build>
<finalName>testdemo</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<configuration>
<server>tomcat6</server>
<url>http://localhost:8080/manager</url>
<path>/testdemo</path>
</configuration>
</plugin>
</plugins>
</build>
在命令行中输入如下命令:
a.切换的项目坐在文件夹
d:
cd workspace/testdemo
b.清理、打包
mvn clean
或
mvn clean install -Dmaven.test.skip=true
c.继续输入命令
mvn tomcat6:run
或
mvn tomcat6:run-war
或
mvn tomcat6:start
在这里将启动tomcat
d.访问http://localhost:8080/testdemoe.停止tomcat
ctrl+c
y
=================================================================
1.在~/.m2/settings.xml中增加如下的Tomcat服务器配置
<servers>
<server>
<id>tomcat6</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
2.法1: 在pom中配置
<build>
<finalName>testdemo</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<configuration>
<server>tomcat6</server>
<url>http://localhost:8080/manager/html</url>
<path>/testdemo</path>
</configuration>
</plugin>
</plugins>
</build>
eclipse如何进断点调试(前提是eclipse安装了maven插件,工程由maven创建,且工程pom.xml中配置了如上所说的tomcat6/7插件):
1. 工程右键-->调试方式-->调试配置-->maven build
2. Maven Build-->新建-->右侧:main-->Base Directory-->Browse Workspace-->点选要调试的工程-->Goals:clean tomcat6:run(如果是tomcat7则输入:tomcat7:run)-->Skip Tests-->应用-->调试(启动过程中会自仓库下载依赖的插件,注意仓库<repositories>配置)
3. 访问url操作
4. 进断点后,如果报找不到源,则点击"编辑源查找路径"-->"添加"-->Java 项目-->确定-->勾选要调试项目-->确定-->确定-->进入断点
更多tomcat6/7的命令请自行查阅:http://tomcat.apache.org/maven-plugin-2/context-goals.html
参考资料:
http://zhoucl.iteye.com/blog/1164495
http://tomcat.apache.org/maven-plugin-2.0-SNAPSHOT/tomcat6-maven-plugin/usage.html
http://tomcat.apache.org/maven-plugin-2/context-goals.html
补充: 如果页面目录不是webapp配置<warSourceDirectory>目录</warSourceDirectory>
<build>
<finalName>testPrj</finalName>
<plugins>
<!-- 本地开发调试 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<warSourceDirectory>WebRoot</warSourceDirectory>
<scanIntervalSeconds>10</scanIntervalSeconds>
<url>http://localhost:8080/manager</url>
<path>/testPrj</path>
<port>8080</port>
<uriEncoding>GBK</uriEncoding>
</configuration>
</plugin>
</plugins>
</build>
打war包,拷贝WEB-INF/lib下的jar包:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warName>${project.artifactId}</warName>
<warName>testPrj</warName>
<webResources>
<resource>
<directory>lib/</directory>
<targetPath>WEB-INF/lib</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>