Maven配置jetty和tomcat部署方式
Tomcat:
http://tomcat.apache.org/maven-plugin-2.2/
命令:http://tomcat.apache.org/maven-plugin-2.2/context-goals.html
pom.xml
<pluginManagement> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> </plugin> </plugins> </pluginManagement>
<pluginManagement> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <url>http://localhost:8080/manager/text</url> <username>admin</username> <password>admin</password> <path>/dev_cpm</path> <!-- 改变端口:mvn tomcat:run -Dmaven.tomcat.port=8081, 也可以使用下面配置 --> <port>8081</port> <!-- 设定内存 --> <systemProperties> <JAVA_OPTS>-Xms256m -Xmx512m -XX:MaxPermSize=256m</JAVA_OPTS> </systemProperties> </configuration> </plugin> </plugins> </pluginManagement>
settings.xml
<pluginGroups> .... <pluginGroup>org.apache.tomcat.maven</pluginGroup> .... </pluginGroups>
命令:
tomcat6:http://tomcat.apache.org/maven-plugin-2.0/tomcat6-maven-plugin/run-mojo.html
tomcat7:https://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/run-mojo.html
tomcat7:run//最新方式
tomcat:run//以前的方式
参数说明:
下面配置也可以类似设置:maven.appserver.home=D:/jakarta-tomcat-5.5.6
其中:maven.appserver.home用于在发布应用时,把打包的部署文件发布到该项指定的目录中的容器环境
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <!-- or if you want to use tomcat 6.x <artifactId>tomcat6-maven-plugin</artifactId> --> <version>2.2</version> <configuration> <!-- http port --> <port>9090</port> <!-- application path always starts with /--> <path>/</path> <!-- optional path to a context file --> <contextFile>${tomcatContextXml}</contextFile> <!-- optional system propoerties you want to add --> <systemProperties> <appserver.base>${project.build.directory}/appserver-base</appserver.base> <appserver.home>${project.build.directory}/appserver-home</appserver.home> <derby.system.home>${project.build.directory}/appserver-base/logs</derby.system.home> <java.io.tmpdir>${project.build.directory}</java.io.tmpdir> </systemProperties> <!-- if you want to use test dependencies rather than only runtime --> <useTestClasspath>false</useTestClasspath> <!-- optional if you want to add some extra directories into the classloader --> <additionalClasspathDirs> <additionalClasspathDir></additionalClasspathDir> </additionalClasspathDirs> </configuration> <!-- For any extra dependencies needed when running embedded Tomcat (not WAR dependencies) add them below --> <dependencies> <dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <version>\${derbyVersion}</version> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4</version> </dependency> </dependencies> </plugin>
jetty:http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin
Eclipse下通过Maven的Jetty插件运行Web工程的配置,包括启动httpshttp://my.oschina.net/cokolin/blog/409164
pom.xml
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.10</version> <configuration> <stopPort>9966</stopPort> <stopKey>foo</stopKey> </configuration> </plugin>
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.3.v20120416</version> <configuration> <webApp> <contextPath>/dev_cpm</contextPath> </webApp> </configuration> </plugin>
或者
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.20</version> <configuration> <contextPath>/jbpm5</contextPath> <!--<webDefaultXml>webdefault.xml</webDefaultXml> --> <scanIntervalSeconds>0</scanIntervalSeconds> <scanTargetPatterns> <scanTargetPattern> <directory>src/main/webapp/WEB-INF</directory> <excludes> <exclude>**/*.jsp</exclude> </excludes> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> </scanTargetPattern> </scanTargetPatterns> </configuration> </plugin>
setting.xml
<profile> ... <pluginGroups> <pluginGroup>org.mortbay.jetty</pluginGroup> </pluginGroups> </profile>
命令:jetty:run
部署方式
1.参考http://www.cnblogs.com/fnng/archive/2011/12/16/2290587.html
2.点击工具条的小虫子,然后选择Debugconfig(调试配置),或者点击项目右键,Debugas(调试方式)-->选择Debugconfig(调试配置),选择MavenBuild,然后点右上角创建一个配置,在Goals输入:jetty:run,这里可以使用多个命令,比如:cleanjetty:run。然后点击debug(调试),开始以Debug方式运行工程。下次运行的时候,不用配置,右键或者点工具栏那里的debug,会多出刚才的这个配置,然后直接运行。
3.使用server(服务器)ofeclipse的方式运行。参考:http://blog.csdn.net/laoshuisheng/article/details/6420003
注意:第2种方式,在包含多Module的时候,很难对代码进行调试,这种情况最好使用的3种。