Eclipse WTP Tomcat hot deploy

转自: 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

时间: 2024-08-09 06:34:25

Eclipse WTP Tomcat hot deploy的相关文章

eclipse启动tomcat无法访问

eclipse启动tomcat无法访问 症状: tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080/不能访问,且报404错误.同时其他项目页面也不能访问. 关闭eclipse里面的tomcat,在tomcat安装目录下双击startup.bat手动启动tomcat服务器.访问htt://localhost:8080/能正常访问tomcat管理页面. 症状原因: eclipse将tomcat的项目发布目录(tomcat 目录中的webapp)重定

eclipse启动tomcat, http://localhost:8080无法访问的解决方案

问题:: tomcat在eclipse里面能正常启动,但在浏览器中访问http://localhost:8080/不能访问tomcat管理页面,且报404错误.同时其他项目页面也不能访问.访问的时候出现下列页面: 现在关闭eclipse里面的tomcat,在tomcat安装目录下双击startup.bat手动启动tomcat服务器.访问htt://localhost:8080/能正常访问下面熟悉的tomcat管理页面,如下所示: 问题原因: 由于eclipse将tomcat的项目发布目录(tom

[转]eclipse启动tomcat无法访问的解决方法

这篇文章介绍了eclipse启动tomcat无法访问的解决方法,有需要的朋友可以参考一下 症状: tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080/不能访问,且报404错误.同时其他项目页面也不能访问. 关闭eclipse里面的tomcat,在tomcat安装目录下双击startup.bat手动启动tomcat服务器.访问htt://localhost:8080/能正常访问tomcat管理页面. 症状原因: eclipse将tomcat的项目

JavaWeb学习(3.5)---Eclipse与Tomcat

一.在Eclipse里配置Tomcat 准备工具: Eclipse J2EE版本(看准了,,standard版本还得另下插件,杯具的我花了一天时间也没装好,最后还是重新下载了J2EE版本,,QAQ) apache-tomcat (这个版本没太大要求,记住版本号方便下一步配置即可)    JDK安装配置之类的网上教程一大堆,这里就不说了,下面直接说在Eclipse里配置Tomcat的步骤.       1.打开eclipse,按照图中所示的点击,File – new – other       

解释Eclipse下Tomcat项目部署路径问题(.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps)

配置eclipse的开发环境,配置jdk的安装路径和tomcat安装路径.在eclipse下建立Dynamic Web Project工程zhgy,在使用eclipse中new一个tomcat,通过启动该tomcat来发布Dynamic Web Project的时候,其实并未将工程发布到tomcat 安装目录所在的 webapps下.这点可以去上述的tomcat 安装目录 的webapps目录下查看.从启动时候的控制台输出来看项目是被发布到了如下的目录: 信息: Set web app root

eclipse与tomcat及javaweb和mysql相关内容

开发了一个web应用好久没看了,都又不知道怎么回事了,怎么当时没有记呢,现在记一下吧. 1.安装eclipse与tomcat,这两个都是解压缩就安装,然后配置相应的环境变量. 2.打开eclipse,window-> perference,配置server->runtime environment,选择对应的tomcat版本,然后设置tomcat的安装路径,ok. 这样就将其关联起来了 3.apache 与tomcat的区别,apache对静态页面的解析较好,tomcat对动态页面解析较好,主

Eclipse下 tomcat 输出路径配置修改 (Java Web发布路径修改/webapps/wtpwebapps)

Eclipse是允许自配置Tomcat来调试Java web的,但是它发布的时候默认不是发布到Tomcat的webapps的目录下,这让我纠结了好久,因为我开始用MyEclipse(但为了保持团队开发工具的统一,现在都改成了Eclipse作为开发工具)开发Java Web时,他会自动部署到webapps目录下,奇怪了,跑到哪去了?问了下同事,也查了下资料,下面的这篇文章帮我找到了解决方案: 在Eclipse下配置server为Tomcat(一般为Tomcat 6.X),双击server面板中的T

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

来了来了~~~~~我们的"织女"--Tomcat来了,牛郎们等急了吧!哈哈! 一.安装Tomcat 下载地址:http://tomcat.apache.org/download-70.cgi 左侧:选择的是Tomcat的版本,这里以Tomcat 7为例. 右边可以选择不同的安装版本,红框部分是windows的zip安装版本, 选择和自己jdk位数一样的位数,进行下载就行了. 安装Tomcat 那就很简单了解压就行了,解压后如下图: 解压后选择 bin目录下面的->startup.

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

以下我所使用的各软件版本为:JDK(1.6):eclipse(3.2.2):myEclipse(5.5.1GA):tomcat(5.5.12): 一.安装JDK: 下载完JDK(1.6)后双击进行安装,安装过程中所有配置保持默认选项.安装完成后如图: 安装完成后配置JDK环境变量:回到桌面,在“我的电脑”上点右键—>“属性”—>“高级”—> “环境变量(N)”. 新建系统变量JAVA_HOME:C:\Program Files\Java\jdk1.6.0_02; 新建系统变量CLASSP