maven3+tomcat7 外部启动 tomcat 和嵌入启动。
编辑于2011-11-28。
参考 http://yingzhuo.iteye.com/ 这位大牛的 http://yingzhuo.iteye.com/blog/1102146 (Maven 与 Tomcat7),折腾了一下,虽然跑通了,但感觉不算太好,比起 jetty 和 maven 的集成使用,还有一段距离。后来搜索到 T7mp,感觉正是我所需要的,极力推荐使用 t7mp http://t7mp.github.com/
以下是配置文件 pom.xml 。
... <build> <outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory> <testOutputDirectory>src/main/webapp/WEB-INF/classes</testOutputDirectory> <finalName>${project.artifactId}-${project.version}</finalName> <testResources> <testResource> <directory>src/test/resources</directory> </testResource> </testResources> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>7.4.2.v20110526</version> <configuration> <webDefaultXml> src/main/resources/webdefault.xml </webDefaultXml> <webAppConfig> <contextPath>/</contextPath> </webAppConfig> <scanIntervalSeconds>0</scanIntervalSeconds> <connectors> <connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector"> <port>443</port> <maxIdleTime>30000</maxIdleTime> <keystore>src/main/resources/server_keystore</keystore> <password>123</password> <keyPassword>123</keyPassword> <truststore>src/main/resources/server_keystore</truststore> <trustPassword>123</trustPassword> <needClientAuth>false</needClientAuth> </connector> <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> <port>82</port> <maxIdleTime>60000</maxIdleTime> <Acceptors>2</Acceptors> <confidentialPort>443</confidentialPort> </connector> </connectors> </configuration> </plugin> <plugin> <groupId>com.googlecode.t7mp</groupId> <artifactId>maven-t7-plugin</artifactId> <version>0.9.8</version> <configuration> <tomcatHttpPort>8080</tomcatHttpPort> <tomcatVersion>7.0.22.A</tomcatVersion> <downloadTomcatExamples>false</downloadTomcatExamples> <contextFile>/target/${project.artifactId}-${project.version}.war</contextFile> <contextPath>/</contextPath> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <version>1.1</version> <configuration /> </plugin> <plugin> <groupId>org.zeroturnaround</groupId> <artifactId>javarebel-maven-plugin</artifactId> <version>1.0.5</version> <executions> <execution> <id>generate-rebel-xml</id> <phase>process-resources</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ...
同时配置了 jetty 和 t7mp,运行时候更简单:mvn t7:run 还不错。
=========================================================================
取代 jetty-env.xml 在 /src/main/tomcat/conf/context.xml 中
... <Resource name="jdbc/postgres" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" loginTimeout="10" username="root" password="pass" maxActive="20" maxIdle="10" maxWait="-1" url="jdbc:postgresql://devdb.mydomain.cn:5432/mydb" /> <Environment name="jsCompress/developMode" type="java.lang.Boolean" value="true" /> ...