1、添加项目
2、选择maven-archetype-webapp
3、添加公司/组织名称,项目名称,版本号
4、补全未生成的文件夹
5、pom.xml中添加jetty插件信息
- <plugins>
- <plugin>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>maven-jetty-plugin</artifactId>
- <version>6.1.9</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>
- </plugins>
6、执行 mvn jett:run
- D:\workspace201408\sshdemo>mvn jetty:run
- [INFO] Scanning for projects...
- [INFO]
- [INFO] ------------------------------------------------------------------------
- [INFO] Building sshdemo Maven Webapp 0.0.1-SNAPSHOT
- [INFO] ------------------------------------------------------------------------
- [INFO]
- [INFO] >>> maven-jetty-plugin:6.1.9:run (default-cli) > test-compile @ sshdemo >>>
- [INFO]
- [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ sshdemo ---
- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
- [INFO] Copying 0 resource
- [INFO]
- [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ sshdemo ---
- [INFO] Nothing to compile - all classes are up to date
- [INFO]
- [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ sshdemo ---
- [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
- [INFO] skip non existing resourceDirectory D:\workspace201408\sshdemo\src\test\resources
- [INFO]
- [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ sshdemo ---
- [INFO] Nothing to compile - all classes are up to date
- [INFO]
- [INFO] <<< maven-jetty-plugin:6.1.9:run (default-cli) < test-compile @ sshdemo <<<
- [INFO]
- [INFO] --- maven-jetty-plugin:6.1.9:run (default-cli) @ sshdemo ---
- [INFO] Configuring Jetty for project: sshdemo Maven Webapp
- [INFO] Webapp source directory = D:\workspace201408\sshdemo\src\main\webapp
- [INFO] web.xml file = D:\workspace201408\sshdemo\src\main\webapp\WEB-INF\web.xml
- [INFO] Classes = D:\workspace201408\sshdemo\target\classes
- [INFO] Logging to org.slf4j.impl.SimpleLogger(org.mortbay.log) via org.mortbay.log.Slf4jLog
- [INFO] Context path = /sshdemo
- [INFO] Tmp directory = determined at runtime
- [INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
- [INFO] Web overrides = none
- [INFO] Webapp directory = D:\workspace201408\sshdemo\src\main\webapp
- [INFO] Starting jetty 6.1.9 ...
- [INFO] jetty-6.1.9
- [INFO] No Transaction manager found - if your webapp requires one, please configure one.
- [INFO] Started SelectChannelConnector@0.0.0.0:8080
- [INFO] Started Jetty Server
7、访问http://localhost:8080/sshdemo/
以上过程是最简单的eclipse + jetty + maven实现一个小的web项目,当然这里jetty其实是一个轻量级的web容器,和tomcat类似。