使用Intell IDEA Debug jetty web应用

以下适合于使用maven管理的web工程,运行在jetty容器下:

1.添加jetty的maven插件

[html]  view plain copy print ?
  1. <plugin>  
  2.    <groupId>org.mortbay.jetty</groupId>  
  3.    <artifactId>maven-jetty-plugin</artifactId>  
  4.    <version>6.1.26</version>  
  5.    <configuration>  
  6.      <connectors>  
  7.      <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">  
  8.          <port>8080</port>  
  9.        </connector>  
  10.      </connectors>  
  11.      <scanIntervalSeconds>10</scanIntervalSeconds>  
  12.    </configuration>  
  13.  </plugin>  
制定了端口号8080和scan间隔
2.在Intell Idea中配置:

Run/Debug Configuration中add 一个maven configuration:


指定项目工程路径,goals设置为jetty:run,同时不要忘记在General和Runner中设置maven路径和jdk

3.启动debug即可

4.如果应用中需要添加数据源,可以直接在maven plugin中指定:

                <jettyEnvXml>src/main/resources/jetty-env-test.xml</jettyEnvXml>

对应的数据源内容可以是:

[html]  view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>    
  2. <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"    
  3. "http://jetty.mortbay.org/configure.dtd">    
  4. <Configure class="org.mortbay.jetty.webapp.WebAppContext">    
  5.     <New id="dataSource" class="org.mortbay.jetty.plus.naming.Resource">    
  6.         <Arg>jdbc/osworkflow</Arg>    
  7.         <Arg>    
  8.             <New class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">    
  9.                 <Set name="url">jdbc:mysql://localhost:3306/osworkflow?useUnicode=true&characterEncoding=UTF-8</Set>    
  10.                 <Set name="user">root</Set>    
  11.                 <Set name="password"></Set>    
  12.             </New>    
  13.         </Arg>    
  14.     </New>    
  15. </Configure>    

当然,如果你的plugin中缺少需要依赖的jar包,也可以在pom文件中配置添加,比如需要dbcp的数据源依赖,那可能你工程中缺少对应jar包,可以如下:

在jetty plungin中假如依赖:

[html]  view plain copy print ?
  1. <plugin>  
  2.            <groupId>org.mortbay.jetty</groupId>  
  3.            <artifactId>maven-jetty-plugin</artifactId>  
  4.            <version>6.1.26</version>  
  5.             <dependencies>  
  6.              <dependency>  
  7.                <groupId>commons-dbcp</groupId>  
  8.                <artifactId>commons-dbcp</artifactId>  
  9.                <version>1.3</version>  
  10.              </dependency>  
  11.             </dependencies>  
  12.            <configuration>  
  13.              <connectors>  
  14.              <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">  
  15.                  <port>8080</port>  
  16.                </connector>  
  17.              </connectors>  
  18.              <jettyEnvXml>src/main/resources/jetty-env-idea.xml</jettyEnvXml>  
  19.              <scanIntervalSeconds>10</scanIntervalSeconds>  
  20.            </configuration>  
  21.          </plugin>  
转自:http://blog.youkuaiyun.com/tobeandnottobe/article/details/7445417
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值