转自: http://ducquoc.wordpress.com/2010/11/06/eclipse-wtp-tomcat-hot-deploy/

One of the reasons why JavaEE does not have many succesful projects is that its development time is usually longer than other competitors’ time (PHP, Ruby, Python, ASP.NET, …) . Ok, we all know the burden of overly complicated design and over-engineered implementations from Sun, so let’s skip them and go to the one to be resolved: the Hot-Deploy time. In other words, the time for developers to see the web-page refreshed with their changes applied.

The word “hot deploy” used above may not reflect its original meaning, not only because my poor English, but also because (Vietnamese) developers have different concepts of it: “automatic hot swap”, “automatic redeploy webapp”, “automatic restart container” .

Hot deploy concepts

This is how I understand the differences:

1/ Hot deploy container: automatic restart whole servlet container (Tomcat)
2/ Hot deploy webapp: automatic reload context root and all classes of respective webapp.
3/ Hot deploy classes: hot-swap only the re-compiled classes (runtime)

It is obvious that #1 is slower than #2 and #2 is slower than #3: Hot-swap or hot-code replacing .

Ok, now what? Let’s try to reduce the hot-deploy time in Java developement in the well-known combination: Eclipse + WTP plugins + Tomcat. Assumed that you already have an Eclipse with WTP/WST plugins installed (e.g. Eclipse JavaEE version).

Create a New Server WTP for web apps

From the New menu, select Other… -> Server -> Server. For your server type (probably “Apache Tomcat 6″), specify the path to your Tomcat installation directory, e.g.“/opt/apache-tomcat-6.0.18″ or “D:\USR\apache-tomcat-6.0.18″ . Add your web project as a ‘Resource’ to this server (you may modify the context root first).

Adjust the server’s settings

Double click on the Server in your Server view (its name is something like “Tomcat v6.0 Server at localhost-config”), it will display the “Overview” tab:

  • Server location: Use Tomcat installation (actually, either “workspace metadata” or“custom location” can work as well, but let’s use the most simple for beginners’ sake)
  • Port: modify the HTTP port from 8080 to the one you desire. You may also modify the remaining 2 ports respectively to avoid port conflicts between Tomcat instances.
  • Timeout: better increase them 100 or 200 seconds more.
  • Server options: not necessary to check any options.

Enable classes hot-swap

The main settings for hot-deploy here:

  • Publishing: Auto publish when resources changes (so as to hot-deploy text resources like .properties, .html, .jsp, … and packaged resources like .jar, .zip ) , the interval should be small (1 or 0 sec).
  • Switch to “Modules” tab, since you already added the web app to the server, there should be at least a “module” with the specified context root (path URL). Select that module, then click “Edit” button, uncheck the “Auto reloading enabled” checkbox, click OK. Now your module should have “Auto Reload” setting as disabled (equivalence to <Context reloadable=”false” … /> in server.xml/context.xml of Tomcat)
  • Save the changes (at least make sure the two above has been applied already).

Start the server in Debug mode

Once you started the web-app in Debug (right click -> choose “Debug…”), the changes you make to your JSPs or inside Java methods will be instantly hotswapped into your running webapp, therefore reduce the development time (at least the wasted time looking at console when reloading web-app)

Why?

Since Java 1.4.2 , the JPDA supports hot-swap classes on debug mode, by manipulating class loaders at runtime. Eclipse makes use of it via WTP under the name Hot Code Replace . Setting auto-publish helps replacing text files and recompiled jar, but not for classes. By default, Tomcat’s context reloading will reload all classes using its class loaders and therefore does not take advantage of hot-deployed classes.
Note that JPDA is not the best solution for hot code replacing, the proven one here must be either JRebel or DynamicCodeEvolution. Some web frameworks (Tapestry, Stripes, Wicket, Grails, Roo) also has their own classloader handlings to support quick reload. They’re all inspired by some standalone JAR files around which I don’t remember (probably the pioneers for JRebel). And FYI, Tomcat Sysdeo plugin and Jetty can also support HCR , in case you don’t want to use Tomcat WTP.

Some more recommended settings

Running Tomcat in Eclipse (via WTP plugin) is a bit slower than via external command, and running in Debug mode is somehow resource-hogging, which may result in errors like hot-swap failure or OutOfMemoryError . To avoid those issues, you may try some JVM options via Tomcat JRE params: Double-click on your server in the “Servers” view, switch to the “Overview” tab, click on the “Open launch configuration” link, switch to the Arguments tab; there you can add relevant memory settings to the “VM Arguments” section
-client -Djava.awt.headless=true
-Xmx1024m
-Xms256m
-XX:MaxPermSize=1024m
-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+UseConcMarkSweepGC

Limitations

JPDA HCR not applied: to change the signature of a class (add/remove methods or fields) or to add new classes on the fly. Additionally, some method calls (“stack frames”) can’t be modified, including the main method or any method invoked via reflection, that is, by usingjava.lang.reflect.Method.invoke().
(JRebel and DynamicCodeEvolution can overcome those limitations)

Eclipse WTP Tomcat hot deploy的更多相关文章

  1. eclipse启动tomcat无法访问

    eclipse启动tomcat无法访问 症状: tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080/不能访问,且报404错误.同时其他项目页面也不能 ...

  2. eclipse启动tomcat, http://localhost:8080无法访问

    原地址 症状: tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080/不能访问,且报404错误.同时其他项目页面也不能访问. 关闭eclipse里面的 ...

  3. 如何在Eclipse和Tomcat的Debug过程中启用热部署

    参考的地址是 http://blog.redfin.com/devblog/2009/09/how_to_set_up_hot_code_replacement_with_tomcat_and_ecl ...

  4. Springmvc+Hibernate在Eclipse启动Tomcat需要很长时间的解决方法

    最近在学习SpringMvc开发,有一个提问困扰了很久,就是在Eclipse启动Tomcat需要很长时间,大概要1分多钟. 启动日志: 九月 08, 2016 8:59:01 下午 org.apach ...

  5. [Eclipse] - 集成Tomcat热加载插件

    使用Eclipse + Tomcat,要使用热加载,总是会重启tomcat webapp. 可以使用这个插件:jrebel 如果是Tomcat 7.0+版本,需要使用jrebel5.5.1+的版本,不 ...

  6. Eclipse 配置Tomcat

    1.Eclipse EE 配置Tomcat Eclipse EE 主要用于Java Web开发和J2EE项目开发.Eclipse EE中配置Tomcat比较简单,新建一个Tomcat Server即可 ...

  7. JDK+Eclipse+MyEclipse+tomcat的安装与配置

    以下我所使用的各软件版本为:JDK(1.6):eclipse(3.2.2):myEclipse(5.5.1GA):tomcat(5.5.12): 一.安装JDK: 下载完JDK(1.6)后双击进行安装 ...

  8. eclipse中tomcat 中server location灰色,如何修改?

    Eclipse中tomcat service设置选择window ----show view---services可以看到服务的面板双击tomcat进入配置界面Service Locations(Sp ...

  9. [知了堂学习笔记]_牵线Eclipse和Tomcat第二篇 —— 安装Tomcat&&添加Tomcat到Eclipse

    来了来了~~~~~我们的"织女"--Tomcat来了,牛郎们等急了吧!哈哈! 一.安装Tomcat 下载地址:http://tomcat.apache.org/download-7 ...

随机推荐

  1. HBase的数据模型相关操作 使用t这个变量来代替table1

    在andriod的应用程序中,用户所感知的都是一个个应用界面,在android程序里面每个应用界面对应一个 Activity类,这类似于.NET Winform项目中的Form窗体.与WinForm中 ...

  2. python学习笔记系列----(五)输入和输出

    这一章主要是讲述程序展示其数据的一些方法,一般都是直接按照一定的格式输出在屏幕,或者写入到文件以便以后使用.按照一定格式的输出,在python中实际就是对str的操作,主要就是介绍了formart() ...

  3. 学习了quartz.net2.0的心得

    由于项目中要运用到此调度方法,所以抽空学习了下,简单的用法可以掌握了 首先作为没有用过的人来说,怎么用呢? 于是百度了下原来先要下载 quartz.net2.0, 然后我就去下了个quartz.net ...

  4. [已解决] MAVEN安装代码到本地库,安装jar, source, javadoc的方式

    mvn install:install-file -Dfile=a.jar -DgroupId=gid -DartifactId=aid -Dversion=0.0.1 -Dpackaging=jar ...

  5. js封装类

    1.闭包函数中定义基类,使用基类定义类方法 ;var Appkit = function() { //定义类 var obj = new Object(); // 定义方法 obj.isWeixin ...

  6. 【原创】在pc端集成地图功能(一)

    在pc端做人员调度功能,用到地图.看了一点高德地图API,由于手机端用的是百度地图,现在需要改用百度地图.下面把看的高德地图一点点成果记录下来: 1.在高德地图开放平台(http://lbs.amap ...

  7. laravel框架总结(九) -- 软删除

    当模型被软删除时,它们并不会真的从数据库中被移除.而是会在模型上设置一个 deleted_at 属性并将其添加到数据库.如果对应模型被软删除,则deleted_at字段的值为删除时间,否则该值为空. ...

  8. Web Performance Test : 为Request的Post参数名添加XPath支持

    问题描述 本文的标题看起来有些含糊其辞,这里我需要把问题阐述得更加清楚.这是我们使用VSTS进行Web Performance Test时,Asp.net造成的特定问题(也许其他开发工具或插件也会造成 ...

  9. WebForm Application Viewstate 以及分页(功能性的知识点)

    Application: 全局公共变量组 存放位置:服务器 特点:所有访问用户都是访问同一个变量,但只要服务器不停机,变量一直存在于服务器的内存中,不要使用循环大量的创建Application对象,可 ...

  10. IE11 iframe alternative

    <OBJECT classid=clsid:8856F961-340A-11D0-A96B-00C04FD705A2> <PARAM NAME=Location VALUE=http ...