Jetty and Maven HelloWorld完成
在看完了Maven权威的前五章以后,我又重新回到了Jetty的学习,刚刚把这两个Jetty的用Maven构建的例子运行完毕。http://wiki.eclipse.org/Jetty/Tutorial/Jetty_and_Maven_HelloWorld
第一个例子:Configuring Embedded Jetty with Maven
#1 使用mvn的archetype构建项目的骨架
mvn archetype:create -DgroupId=com.licanjing.jetty.study -DartifactId=helloWorld -DpackageName=com.licanjing.jetty.study -Dversion=1.0
删除App.java和AppTest.java
#2 在com.licanjing.jetty.study目录建立HelloWorld.java
#3 在pom.xml中加入对jetty-server和servlet的依赖和exec:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>7.1.6.v20100715</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.4_spec</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution><goals><goal>java</goal></goals></execution>
</executions>
<configuration>
<mainClass>com.licanjing.jetty.study.HelloWorld</mainClass>
</configuration>
</plugin>
</plugins>
</build>
#4 运行
mvn clean compile exec
:java
#5 在浏览器查看结果:http://localhost:8080/
第二个例子:Developing a Standard WebApp with Jetty and Maven
#1使用mvn archetype创建web app的骨架
mvn archetype:create -DgroupId=com.licanjing.jetty.study -DartifactId=helloWebApp -Dpackage=com.licanjing.jetty.study -DarchetypeArtifactId=maven-archetype-webapp
#2 删除index.jsp, 创建index.html
原文中好像有点错误,html里面应该为:
<h1>Hello World Webapp</h1>
<a href="/helloWebApp/hello">Hello Servlet</a>
#3 创建HelloServlet.java
#4 修改web.xml
#5 修改pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.4_spec</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>helloWebApp</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
#6 运行mvn jetty:run
#7 在浏览器中查看结果 http://localhost:8080/helloWebApp/
页:
[1]