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/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值