`
zhangjunji111
  • 浏览: 46734 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

直接在ECLIPSE中JETTY调试方式

 
阅读更多

1.创建项目

mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp

也可参看这里

创建要注意遵循MAVEN的目录结构,尤其要注意源文件要放在main/java下:



2. POM文件的配置

这里要特别注意对resource一节的配置,因为我的SPRING以及WEB相关的XML是放在WEB-INF目录,为了在unit test的时候也能用,加入了对这些配置文件的引用。相当于加了一个classpath。

这里还有个插曲:不知为何MAVEN2里没有JTA的包,自动下载时会有提示教你如何手工通过命令加入,非常简单。

JETTY的plugin是为后面用它来调试做准备。

DWR也是目前WEB开发一个热选。

另外,为使用JAVA5代来编译,加入了maven-compiler-plugin一节。

< project  xmlns ="http://maven.apache.org/POM/4.0.0"  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation
="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >
  
< modelVersion > 4.0.0 </ modelVersion >
  
< groupId > com.exchangebit.nms </ groupId >
  
< artifactId > ebnms </ artifactId >
  
< packaging > war </ packaging >
  
< version > 1.0-SNAPSHOT </ version >
  
< name > ebnms Maven Webapp </ name >
  
< url > http://maven.apache.org </ url >
      
  
< build >
    
< finalName > ebnms </ finalName >
    
      
< resources >
        
< resource >
          
< directory > src/main/java </ directory >
          
< includes >
            
< include > **/*.xml </ include >
          
</ includes >
        
</ resource >
        
< resource >
          
< directory > src/main/webapp/WEB-INF </ directory >
          
< includes >
            
< include > **/*.xml </ include >
            
< include > **/log4j.properties </ include >
          
</ includes >
        
</ resource >
      
</ resources >
      
      
< plugins >
        
< plugin >
          
< groupId > org.apache.maven.plugins </ groupId >
          
< artifactId > maven-compiler-plugin </ artifactId >
          
< configuration >
            
< source > 1.5 </ source >
            
< target > 1.5 </ target >
          
</ configuration >
        
</ plugin >
        
      
< plugin >
        
< groupId > org.mortbay.jetty </ groupId >
        
< artifactId > maven-jetty-plugin </ artifactId >
      
</ plugin >         
  
      
</ plugins >
    
</ build >     
      
  
< dependencies >
    
< dependency >
      
< groupId > junit </ groupId >
      
< artifactId > junit </ artifactId >
      
< version > 3.8.1 </ version >
      
< scope > test </ scope >
    
</ dependency >
        
    
< dependency >
      
< groupId > org.hibernate </ groupId >
      
< artifactId > hibernate </ artifactId >
      
< version > 3.1 </ version >
    
</ dependency >
    
    
< dependency >
      
< groupId > log4j </ groupId >
      
< artifactId > log4j </ artifactId >
      
< version > 1.2.11 </ version >
    
</ dependency >
    
< dependency >
      
< groupId > mysql </ groupId >
      
< artifactId > mysql-connector-java </ artifactId >
      
< version > 3.1.11 </ version >
      
< scope > runtime </ scope >
    
</ dependency >
    
< dependency >
      
< groupId > javax.servlet </ groupId >
      
< artifactId > servlet-api </ artifactId >
      
< version > 2.4 </ version >
      
< scope > provided </ scope >
    
</ dependency >
    
< dependency >
      
< groupId > javax.servlet </ groupId >
      
< artifactId > jstl </ artifactId >
      
< version > 1.1.2 </ version >
      
< scope > runtime </ scope >
    
</ dependency >
    
< dependency >
      
< groupId > taglibs </ groupId >
      
< artifactId > standard </ artifactId >
      
< version > 1.1.2 </ version >
      
< scope > runtime </ scope >
    
</ dependency >
    
< dependency >
      
< groupId > org.springframework </ groupId >
      
< artifactId > spring </ artifactId >
      
< version > 1.2.6 </ version >
    
</ dependency >
        
    
< dependency >
      
< groupId > dwr </ groupId >
      
< artifactId > dwr </ artifactId >
      
< version > 1.1.3 </ version >
    
</ dependency >         
  
</ dependencies >
  
</ project >



代码放入/main/java后,可以在项目目录下执行:
mvn compile来做编译尝试,
也可以用mvn war直接生成打包文件,
当然最后可以用 mvn jetty:run来运行你的WEBAPP!


3.  在Eclipse中配置jetty进行调试
要把之前的项目导入Eclipse首先让maven为我们生成Eclipse工程文件,执行:
mvn eclipse:eclipse
再把M2_REPO加入到Eclipse的classpath中,有两种方法,其中的b)方法是有效的:
a) mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo
b) Window > Preferences. Select the Java > Build Path > Classpath Variables page


之后,就可以通过Eclipse的File->Import功能将工程导入。


有人为了使用WEBAPP开发功能,而装象MYECLIPSE这样的巨物。有了JETTY,通过轻松配置就可以实现比TOMCAT更快更便捷的容器,所以在调试时强力推荐这个东东。下面就来看下如何配置。

先下配置一个外部工具,来运行JETTY:
选择菜单Run->External Tools->External Tools ...在左边选择Program,再点New:
配置Location为mvn完整命令行。

选择Working Directory为本项目。

Arguments填写:jetty:run

再点选Enviroment页:加入MAVEN_OPTS变量,值为:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y
其中,如果suspend=n 表示不调试,直接运行。

然后,点APPLY,再关闭本对话框。
另外注意一点,好像external tool菜单项在java browering的perspective下才会出现。如果在java下看不见,可以切换下试试。



下面新建运行配置:
点选run->debug...
选中左树中的Remote Java Application,再点New。
选择你的项目,关键是要填和之前设置外部工具时相同的端口号。





配置就完成了,正面开始调试运行:
首先要把JETTY运行起来(有点象TOMCAT里的运行APPSERVER),从Run->External Tools中选择之前配置的外部工具运行,这时LOG里会显示:
listening at port 4000字样,
再选择Run->Debug选择我们刚建的运行配置,这时程序就RUN起来了,可以通过WEB进行访问,设置断点调试了。



 ============================================================================

适用于6.1.3以上,包括6.1.5的JETTY。

它主要是利用了JDK的代码自动更换性能(code hot replace),可以不用重启JETTY就调试、更换资源文件。注意:一定是DEBUG方式运行才有这项功能。

所以应该说这篇文章的方法更好:

在Run->Debug中,New一个Java Application的配置,填入:

org.mortbay.xml.XmlConfiguration

参数填入一个自己的JETTY配置文件:




完成的myjetty.xml配置文件,请将其中的相应目录修改成自己项目的目录:

<? xml version="1.0" ?>
<! DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd" >

<!--  ===============================================================  -->
<!--  Configure the Jetty Server                                       -->
<!--                                                                   -->
<!--  Documentation of this file format can be found at:               -->
<!--  http://docs.codehaus.org/display/JETTY/jetty.xml                 -->
<!--                                                                   -->
<!--  ===============================================================  -->


< Configure  id ="Server"  class ="org.mortbay.jetty.Server" >

    
<!--  ===========================================================  -->
    
<!--  Server Thread Pool                                           -->
    
<!--  ===========================================================  -->
    
< Set  name ="ThreadPool" >
      
<!--  Default bounded blocking threadpool 
      
-->
      
< New  class ="org.mortbay.thread.BoundedThreadPool" >
        
< Set  name ="minThreads" > 10 </ Set >
        
< Set  name ="maxThreads" > 250 </ Set >
        
< Set  name ="lowThreads" > 25 </ Set >
      
</ New >

      
<!--  Optional Java 5 bounded threadpool with job queue 
      <New class="org.mortbay.thread.concurrent.ThreadPool">
        <Set name="corePoolSize">250</Set>
        <Set name="maximumPoolSize">250</Set>
      </New>
      
-->
    
</ Set >



    
<!--  ===========================================================  -->
    
<!--  Set connectors                                               -->
    
<!--  ===========================================================  -->
    
<!--  One of each type!                                            -->
    
<!--  ===========================================================  -->

    
<!--  Use this connector for many frequently idle connections
         and for threadless continuations.
    
-->     
    
< Call  name ="addConnector" >
      
< Arg >
          
< New  class ="org.mortbay.jetty.nio.SelectChannelConnector" >
            
< Set  name ="port" >< SystemProperty  name ="jetty.port"  default ="8080" /></ Set >
            
< Set  name ="maxIdleTime" > 30000 </ Set >
            
< Set  name ="Acceptors" > 2 </ Set >
            
< Set  name ="statsOn" > false </ Set >
            
< Set  name ="confidentialPort" > 8443 </ Set >
        
< Set  name ="lowResourcesConnections" > 5000 </ Set >
        
< Set  name ="lowResourcesMaxIdleTime" > 5000 </ Set >
          
</ New >
      
</ Arg >
    
</ Call >

    
<!--  Use this connector if NIO is not available.
    <Call name="addConnector">
      <Arg>
          <New class="org.mortbay.jetty.bio.SocketConnector">
            <Set name="port">8081</Set>
            <Set name="maxIdleTime">50000</Set>
            <Set name="lowResourceMaxIdleTime">1500</Set>
          </New>
      </Arg>
    </Call>
    
-->

    
<!--  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  -->
    
<!--  To add a HTTPS SSL listener                                      -->
    
<!--  see jetty-ssl.xml to add an ssl connector. use                   -->
    
<!--  java -jar start.jar etc/jetty.xml etc/jetty-ssl.xml              -->
    
<!--  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  -->
    
    
<!--  ===========================================================  -->
    
<!--  Set up global session ID manager                             -->
    
<!--  ===========================================================  -->
    
<!--
    <Set name="sessionIdManager">
      <New class="org.mortbay.jetty.servlet.HashSessionIdManager">
        <Set name="workerName">node1</Set>
      </New>
    </Set>
    
-->

    
<!--  ===========================================================  -->
    
<!--  Set handler Collection Structure                             -->  
    
<!--  ===========================================================  -->
    
< Set  name ="handler" >
      
< New  id ="Handlers"  class ="org.mortbay.jetty.handler.HandlerCollection" >
        
< Set  name ="handlers" >
         
< Array  type ="org.mortbay.jetty.Handler" >
           
< Item >
             
< New  id ="Contexts"  class ="org.mortbay.jetty.handler.ContextHandlerCollection" />
           
</ Item >
           
< Item >
             
< New  id ="DefaultHandler"  class ="org.mortbay.jetty.handler.DefaultHandler" />
           
</ Item >
           
< Item >
             
< New  id ="RequestLog"  class ="org.mortbay.jetty.handler.RequestLogHandler" />
           
</ Item >
         
</ Array >
        
</ Set >
      
</ New >
    
</ Set >
    
< Set  name ="handler" >    
  
< New  id ="Handlers"  class ="org.mortbay.jetty.handler.HandlerCollection" >    
    
< Set  name ="handlers" >    
      
< Array  type ="org.mortbay.jetty.Handler" >    
        
<!-- Item>   
          <New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/>   
        </Item
-->    
        
< Item >    
          
< New  class ="org.mortbay.jetty.webapp.WebAppContext" >    
            
< Set  name ="contextPath" > /ebnms </ Set >    
            
< Set  name ="resourceBase" > E:/Prj2/ForMe/Src/flower/src/main/webapp </ Set >    
            
< Call  name ="addServlet" >    
              
< Arg > org.mortbay.jetty.servlet.DefaultServlet </ Arg >    
              
< Arg > / </ Arg >    
            
</ Call >    
          
</ New >    
    
</ Item >    
      
</ Array >    
    
</ Set >    
  
</ New >    
</ Set >    


    
<!--  ===========================================================  -->
    
<!--  Configure Authentication Realms                              -->
    
<!--  Realms may be configured for the entire server here, or      -->
    
<!--  they can be configured for a specific web app in a context   -->
    
<!--  configuration (see $(jetty.home)/contexts/test.xml for an    -->
    
<!--  example).                                                    -->
    
<!--  ===========================================================  -->
    
< Set  name ="UserRealms" >
      
< Array  type ="org.mortbay.jetty.security.UserRealm" >
        
<!--
        <Item>
          <New class="org.mortbay.jetty.security.HashUserRealm">
            <Set name="name">Test Realm</Set>
            <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
          </New>
        </Item>
    
-->
      
</ Array >
    
</ Set >

    
<!--  ===========================================================  -->
    
<!--  Configure Request Log                                        -->
    
<!--  Request logs  may be configured for the entire server here,  -->
    
<!--  or they can be configured for a specific web app in a        -->
    
<!--  contexts configuration (see $(jetty.home)/contexts/test.xml  -->
    
<!--  for an example).                                             -->
    
<!--  ===========================================================  -->
    
<!-- Ref id="RequestLog">
      <Set name="requestLog">
        <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
          <Set name="filename"><SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.request.log</Set>
          <Set name="filenameDateFormat">yyyy_MM_dd</Set>
          <Set name="retainDays">90</Set>
          <Set name="append">true</Set>
          <Set name="extended">true</Set>
          <Set name="logCookies">false</Set>
          <Set name="LogTimeZone">GMT</Set>
        </New>
      </Set>
    </Ref
-->

    
<!--  ===========================================================  -->
    
<!--  extra options                                                -->
    
<!--  ===========================================================  -->
    
< Set  name ="stopAtShutdown" > true </ Set >
    
< Set  name ="sendServerVersion" > true </ Set >
    
<!-- Set name="sendDateHeader">true</Set -->
    
<!-- Set name="gracefulShutdown">1000</Set -->
</ Configure >

  1. Maven
    1. 创建普通工程:mvn archetype:create -DgroupId=com.example -DartifactId=example
    2. 创建Web工程:mvn archetype:create -DgroupId=com.example -DartifactId=example -DarchetypeArtifactId=maven-archetype-webapp
  2. eclipse
    1. 转为eclipse工程:mvn eclipse:eclipse
    2. 添加repository路径变量m2_repo:mvn eclipse:add-maven-repo -Declipse.workspace=your eclipse workspace path
  3. Jetty
    1. 修改POM.xml文件,指定工程使用Jetty及Java5
    xml 代码
    1. < build >   
    2.      < finalName > example finalName >   
    3.      < plugins >   
    4.          < plugin >   
    5.              < groupId > org.apache.maven.plugins groupId >   
    6.              < artifactId > maven-compiler-plugin artifactId >   
    7.              < configuration >   
    8.                  < source > 1.5 source >   
    9.                  < target > 1.5 target >   
    10.              configuration >   
    11.          plugin >   
    12.          < plugin >   
    13.              < groupId > org.mortbay.jetty groupId >   
    14.              < artifactId > maven-jetty-plugin artifactId >   
    15.          plugin >   
    16.      plugins >   
    17. build >   

    2. 工程调试:添加外部工具
    Step 1
    Go to the Run/External Tools/External Tools ..." menu item on the "Run" menu bar. Select "Program" and click the "New" button. On the "Main" tab, fill in the "Location:" as the full path to your "mvn" executable. For the "Working Directory:" select the workspace that matches your webapp. For "Arguments:" add jetty:run .

    Move to the "Environment" tab and click the "New" button to add a new variable named MAVEN_OPTS with the value:

    -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n

    If you supply suspend=n instead of suspend=y you can start immediately without running the debugger and launch the debugger at anytime you really wish to debug.

    Step 2
    Then, pull up the "Run/Debug/Debug ..." menu item and select "Remote Java Application" and click the "New" button. Fill in the dialog by selecting your webapp project for the "Project:" field, and ensure you are using the same port number as you specified in the address= property above.

    Now all you need to do is to Run/External Tools and select the name of the maven tool setup you created in step 1 to start the plugin and then Run/Debug and select the name of the debug setup you setup in step2.

    3. js、css等静态文件无法更新的问题(save could not be completed )
    原文出处
    Jetty启动后,如果修改javascript文件,将不能保存,使调试很麻烦。这是因为使用了CACHE,JETTY说是WINDOWS下的一个限制。可以通过如下方法修正:
    解压出jetty.jar中的 org/mortbay/jetty/webapp/webdefault.xml文件,将这一选项由true改为false,另存到src/main/resources目录,或者其它自选目录。

    xml 代码

    <!-- change to false -->

    1. < init-param >   < param-name > useFileMappedBuffer param-name >  
    2. < param-value > true param-value >   <!-- change to false -->   init-param >   

     在pom.xml中加入对这个文件的指向:

    xml 代码
    1. < plugin >   
    2.   < groupId > org.mortbay.jettygroupId >   
    3.   < artifactId > maven-jetty-pluginartifactId >   
    4.   < configuration >   
    5.     < webDefaultXml > src/main/resources/webdefault.xmlwebDefaultXml >   
    6.   >   
    7. >    
分享到:
评论

相关推荐

    Eclipse与jetty插件的安装和使用

    要安装jetty插件,需要在Eclipse中添加新的软件站点。具体步骤如下: 1. 启动Eclipse,点击Help-&gt; Install New Software,然后选择Add,输入名称为“jetty”的新的更新站点,URL为...

    eclipse中配置使用jetty调试web项目

    NULL 博文链接:https://bingyingao.iteye.com/blog/1277090

    eclipse 整合 jetty 调试

    NULL 博文链接:https://xq0804200134.iteye.com/blog/1812468

    eclipse-jetty 3.9.0 eclipse的jetty插件 离线安装包

    比run-jetty-run启动要快,但是调试没有run-jetty-run方便。 eclipse插件 离线安装包 Eclipse中Install New Software 然后Add -&gt; Archive,选择该包安装即可 此为最新的3.9.0版。 支持eclipse Neon (4.6), Mars (4.5...

    eclipse jetty插件

    run-jetty-run是一个新的jetty eclipse插件通过该插件可以直接在Eclipse环境中启动、停止 Jetty ,同时进行在线调试而无需重启服务。 http://run-jetty-run.googlecode.com/svn/trunk/updatesite 由于谷歌退出中国,...

    Eclipse3.6与m2eclipse,run-jetty-run插件对WEB项目进行热部署以及在jar源码中进行调试

    Eclipse3.6与m2eclipse,run-jetty-run插件对WEB项目进行热部署以及在jar源码中进行调试

    Java Eclipse ee集合jetty和配置

    在 Eclipse EE 中,Jetty 是一个内置的服务器,可以用来运行和调试 Web 应用程序。在配置 Jetty 时,需要配置 Jetty 服务器的启动参数、 JVM 参数、日志记录等设置。 在给定的文件中,看到的是 Jetty 的启动命令,...

    run-jetty-run

    run-jetty-run是一个新的jetty eclipse插件通过该插件可以直接在Eclipse环境中启动、停止 Jetty ,同时进行在线调试而无需重启服务。

    jetty调试插件

    jetty插件,用于eclipse,可以用来部署网站,以及调试

    maven的入门使用

    maven入门使用 maven创建web项目 maven生成eclipse项目 maven+jetty的使用 jetty在eclipse的配置和使用

    GeoServer开发手册系列

    在Eclipse中运行GeoServer 12 访问GeoServer首页 13 Maven指南 13 安装Maven 13 运行Maven 13 构建 13 跳过测试 14 离线构建 14 构建扩展 14 Profiles 15 Eclipse 15 构建Web模块 15 使用Jetty运行web模块 16 ...

    connect-1.2-all-in-one

    vi)在Eclipse中右键项目,选择Configure --&gt; Convert to Maven Project vii)运行项目。右键项目,run as maven build... --&gt; Goals: jetty:run #启动配置 前提准备,已经申请到QQ互联的APP_ID, APP_KEY i)...

    基于SSH 框架,可成功部署于新浪SAE java的Demo

    6、SAE 的 Java环境是基于 jetty ,可以先在本地运行jetty进行调试。 7、sae-eclipse.zip 里面是sae 的eclipse插件,官方有教程如何使用,可以方便更新文件。 8、如果有任何疑问,可以联系deejac@qq.com 有问必答 ...

    formio-demo:Formio,Java表单定义和绑定库的演示

    从Eclipse运行-在“调试配置”中设置以下参数: 项目:formio-demo(浏览以找到项目) 主类:net.formio.demo.HttpServer VM参数:-XXaltjvm = dcevm -javaagent:c:/java/hotswap-agent.jar(在使用...

    [计算机毕业设计]基于SSM的古诗词数字化平台(源码+部署说明+演示视频+包运行).zip

    这是一个基于SSM(Spring+Spring MVC+MyBatis)技术的古诗词数字化平台的毕业设计项目。本项目旨在通过将古诗词资源...* 在Tomcat或Jetty等服务器上部署项目,配置相关参数(如端口号、数据库连接信息等)。 5. 演示视频:

    connect-1.3.0-all-in-one

    * 可以直接导入Eclipse Dynamic Web Project项目名demo-nop * 或手动拷贝相关文件至您熟悉的环境(以Eclipse Web项目为例,我们叫这个项目为Q项目) # 下载connect-1.x-all-in-one.zip,解压至当前文件夹 # 拷贝...

    maven学习资料汇总

    里面包含:两本maven电子书(《Maven权威指南中文版》和《Maven实战》)和两个文档(《在maven和jetty环境下eclipse的调试》、《基于Maven的Spring_+_Spring_MVC_+_Mybatis的环境搭建》),内容皆精品。

    [计算机毕业设计]基于SSM的学校小卖部收银系统(源码+部署说明+演示视频+包运行).zip

    * 在Tomcat或Jetty等服务器上部署项目,配置相关参数(如端口号、数据库连接信息等)。 5. 演示视频: 本项目提供了一段演示视频,展示了平台的基本功能和使用方法。观看视频可以帮助用户更直观地了解项目的实现细节...

    tomcat-maven-plugin

    maven-tomcat-plugin让maven与tomcat配合得很好。它可以把应用部署到Tomcat服务器,也可以把tomcat作为内嵌服务器启动,就像jetty一样。...这样就能与eclipse配合起来,轻松地实现调试。而且具有tomcat的热部署功能。

Global site tag (gtag.js) - Google Analytics