1.用mvn创建一个web应用。
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeVersion=1.0 -DgroupId=com.amuse.web.timer -DartifactId=timer -Dversion=1.0
2.添加mvn-jetty插件。
修改pom文件,在pom文件里添加下面这段xml文件片段,见jetty的帮助文档:http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
3.运行mvn install
进入工程目录timer目录下:
mvn install
4.运行mvn jetty:run
mvn jetty:run
5.查看是否成功
在浏览器里输入:http://localhost:8080/timer
如果出现了
Hello World!
表示成功了。
6.生成eclipse工程
mvn eclipse:eclipse
然后导入eclipse里
7.添加servet依赖
<!-- serlvet api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
再执行一次
mvn eclipse:eclipse
给eclipse的添加Referenced Libraries
PS:可以结合 http://wenku.baidu.com/view/0c1cdd886529647d2728521c这篇文档看下
8.下面一篇将会利用本篇的web工程做一个定时器的小例子 |