jetty的安装

插件

方法一:

eclipse 更新地址:http://run-jetty-run.googlecode.com/svn/trunk/updatesite/

 

方法二:

利用SVN 更新地址:http://run-jetty-run.googlecode.com/svn/trunk/updatesite/,然后已link方式到eclipse中

 

 

jar包依赖 java程序启动

创建maven项目 mvn archetype:create -DgroupId=cn.everlook.myweb -DartifactId=myweb -DpackageName=cn.everlook.myweb

                         mvn archetype:create -DgroupId=cn.everlook.myweb -DartifactId=myweb -DarchetypeArtifactId=maven-archetype-webapp

pom.xml配置

  1.依赖jar包

  <!-- jetty -->
  <dependency>
   <groupId>org.eclipse.jetty.aggregate</groupId>
   <artifactId>jetty-webapp</artifactId>
   <version>${jetty.version}</version>
   <scope>compile</scope>
  </dependency>
  <dependency>
   <groupId>org.eclipse.jetty</groupId>
   <artifactId>jetty-jsp</artifactId>
   <version>${jetty.version}</version>
   <scope>compile</scope>
  </dependency>
  <!-- TEST end -->

 2.相关插件

  <artifactId>system</artifactId>

 

   <!-- jetty插件, 设定context path与spring profile -->
   <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${jetty.version}</version>
    <configuration>
     <systemProperties>
      <systemProperty>
       <name>spring.profiles.active</name>
       <value>development</value>
      </systemProperty>
     </systemProperties>
     <useTestClasspath>true</useTestClasspath>

     <webAppConfig>
      <contextPath>/${project.artifactId}</contextPath>
     </webAppConfig>
    </configuration>
   </plugin>

 

   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <configuration>
     <executable>java</executable>
     <arguments>
      <argument>-Xms1024m</argument>
      <argument>-XX:PermSize=128m</argument>
      <argument>-XX:MaxNewSize=512m</argument>
      <argument>-XX:MaxPermSize=256m</argument>
      <argument>-classpath</argument>
      <classpath />
      <argument>com.bamboo.common.jetty.QuickStartServer</argument> <!-- 程序入口,主类名称 -->
     </arguments>
    </configuration>
   </plugin>

 

package com.bamboo.common.jetty;

import org.eclipse.jetty.server.Server;

/**
 * 使用Jetty运行调试Web应用, 在Console输入回车快速重新加载应用.
 *
 * @author calvin
 */
public class QuickStartServer {

 public static final int PORT = 9090;
 public static final String CONTEXT = "/alex";
 public static final String[] TLD_JAR_NAMES = new String[] { "sitemesh", "spring-webmvc", "shiro-web" };

 public static void main(String[] args) throws Exception {
  // 设定Spring的profile
  System.setProperty("spring.profiles.active", "development");

  // 启动Jetty
  long startTime = System.currentTimeMillis();
  Server server = JettyFactory.createServerInSource(PORT, CONTEXT);
  JettyFactory.setTldJarNames(server, TLD_JAR_NAMES);

  try { 
   server.start();
   
   long time = System.currentTimeMillis() - startTime;
   System.out.println("Server startup in " + time + " ms, running at http://localhost:" + PORT + CONTEXT);
   System.out.println("Hit Enter to reload the application quickly");
   
   // 等待用户输入回车重载应用.
   while (true) {
    char c = (char) System.in.read();
    if (c == '\n') {
     JettyFactory.reloadContext(server);
    }
   }
  } catch (Exception e) {
   e.printStackTrace();
   System.exit(-1);
  }
 }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值