Eclipse WTP Tomcat Hot Deploy

Source: Internet
Author: User
Tags apache tomcat

Transferred from: http://ducquoc.wordpress.com/2010/11/06/eclipse-wtp-tomcat-hot-deploy/
One of the reasons why Java EE does not has many succesful projects is that it development time is usually longer than OT Her competitors ' time (PHP, Ruby, Python, ASP.). Ok, we all know the burden of overly complicated design and over-engineered implementations from Sun, so let's skip them a nd go to 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 is not reflect it original meaning, not only because my poor 中文版, but also because (Vietnamese) Developers has different concepts of it: "Automatic hot Swap", "Automatic Redeploy WebApp", "Automatic Resta RT container ".

Hot Deploy Concepts

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 this #1 is slower than #2 and #2 is slower than #3: hot-swap or Hot-code replacing .

Ok, what's now? Let's try to reduce the hot-deploy time in Java developement in the well-known combination:eclipse + WTP plugins + Tomcat . Assumed that already has an Eclipse with WTP/WST plugins installed (e.g. Eclipse Java EE 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/a Pache-tomcat-6.0.18″ or "D:\usr\apache-tomcat-6.0.18″ . ADD your Web project as a ' Resource ' to this server (your may modify the context root first).

Adjust The server ' s settings

Double Click on the server in your server view (its name was something like "Tomcat v6.0 server at Localhost-config" ), it'll 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 beginners ' sake)
    • Port:modify the HTTP port from 8080 to the one desire. Also modify the remaining 2 ports respectively to avoid port conflicts between Tomcat instances.
    • Timeout:better increase them or seconds more.
    • Server Options:not necessary to check the 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 is small (1 or 0 sec).
    • Switch to ' Modules ' tab, since already added the Web app to the server, there should is at least a ' module ' with the S Pecified context root (path URL). Select the module, then click the "Edit" button, uncheck the "Auto reloading Enabled" checkbox, click OK. Now your module should has "Auto Reload" setting as Disabled (equivalence to <context reloadable= "false" .../& Gt In server.xml/context.xml of Tomcat)
    • Save the changes (at least make sure the both above has been applied already).
Start the server in Debug mode

Once started the Web-app in debug (right click-Choose "Debug ..."), the changes you do to your JSPs or inside Jav A methods'll is instantly hotswapped into your running WebApp, therefore reduce the development time (at least the waste D 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 would reload all classes using its class loaders and therefore does not take Advanta GE of hot-deployed classes.
Note that JPDA isn't the best solution for hot code replacing, and the proven one here must be either JRebel or Dynamiccodeev Olution. Some Web Frameworks (Tapestry, stripes, Wicket, Grails, Roo) also have their own ClassLoader handlings to support quick rel Oad. 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) are 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 could try some JVM options via Tomcat JRE Params:double-click on your server in the "Servers" VI EW, switch to the ' Overview ' tab, click on the ' Open launch configuration ' link, switch to the Arguments tab; There 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 FL Y. Additionally, some method calls ("stack frames") can ' t be modified, including the main method or any method invoked via Reflection, that's, by using java.lang.reflect.method.invoke () .
(JRebel And dynamiccodeevolution can overcome those limitations)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.