Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Editing Java webapps instead of edit/deploy/reload

For the last few years, I've always done Java webapp development the hard way. Yeah, I'm the guy that makes Dion cringe (although I'm pretty sure he's not referring directly to me). I edit a class/jsp/xml file and run "ant deploy reload". Then I wait a few seconds for my context to reload in Tomcat. Luckily, I do mostly test-first development, so it's rare that I have to open my browser to test stuff. However, with the power of CSS and Ajax, manual testing in a browser is becoming more and more useful (although Selenium may solve that).

I've long resisted the power of the IDE, b/c I've always trusted Ant and felt confortable with the command line. However, I'm ready for a change. I'm ready to start developing Equinox and AppFuse-based applications using the edit/save/auto-reload cycle. So how do I get started? Where's the instructions for setting up my IDEs to work this way?

I prefer to use Eclipse and IDEA for development - so I'll likely try to get this working in both. If I get it working, I'll make sure and provide good documentation so others can do the same. I'm also willing to make any changes in project structure to make this happen; modifying build.xml (or pom.xml) to accomodate shouldn't be too difficult.

Posted in Java at Nov 07 2005, 09:16:03 AM MST 23 Comments
Comments:

[Trackback] Dions thought provoking blog entry on Refactoring tools are fantastic and overrated inspired me to think more in-depth about the deploy/redeploy nature of Java web development. He makes the point that while tools like IDEA have great refactoring, tha...

Posted by Todd Huss on November 07, 2005 at 08:54 PM MST #

Matt, The setup we use is that our directory structure is pretty close to an exploded war. Then we turn auto class reloading on in Tomcat by adding a line for the app to server.xml such as <Context path="/myapp" docBase="c:/java/myapp/src/webapp" reloadable="true">. Lastly we have have IDEA build the .class files on save into the exploded WARs WEB-INF/classes directory. This allows editing of JSP and Java files and then simply hitting refresh in the browser. Config changes such as properties files and Spring files require hitting a reload in the tomcat admin console or we do a "maven tomcat:reload". We're not using the IDEA Tomcat integration, mainly because once you have auto class reloading on you rarely need to go to the command line or redeploy.

Posted by Todd Huss on November 07, 2005 at 09:07 PM MST #

? Like http://localhost/manager/reload?path=/ and point tomcat webapp xml to your eclipse WEB-INF?

Isn't everyone doing it?

.V

Posted by Vic on November 07, 2005 at 09:52 PM MST #

That is all you need, you only need to restart the server if you change any loaded class interface (on debug mode). Jsp, css, gif... they all're realtime updated. http://eclipse-plugins.2y.net/eclipse/plugin_details.jsp?id=312

Posted by Juze Peleteiro on November 07, 2005 at 10:52 PM MST #

In my opinion is a good move. I've just started to look at appfuse and found inconvenient the "ant deploy reload" cycle. The setup that we usually use is similar to the one suggested by Todd Huss. Note that if you configure IDEA Tomcat integration and debug the project, the IDE automatically reloads modified classes (regardless of server's settings, I think). I don't know how this can be done in eclipse but I'm trying now.

Posted by pic on November 07, 2005 at 11:17 PM MST #

Try this: http://www.myeclipseide.com It very cheap and is really good at dynamic reloading. I'm actually a bigger fan of using ant though because it is easier to transition to continuous build servers if your ant setup is working well. Also, you can call ant straight from eclipse to do your "deploy" (and periodically do a reload when you need it).

Posted by Keith Weinberg on November 08, 2005 at 12:51 AM MST #

yes, myeclipse is very cheap and perhaps I'll buy it eventually. For the moment eclipse + server models in WST work pretty well (exploiting Tomcat's auto class reloading feature).

Posted by pic on November 08, 2005 at 01:42 AM MST #

You should try Sysdeo Eclipse Tomcat Launcher plugin (http://www.sysdeo.com/eclipse/tomcatplugin). It allows you to change code on runtime using an special classloader (http://www.sysdeo.net/eclipse/readmeDevLoader.html), so you can debug, change code, save and continue debugging the same method (if you compile to a different folder than WEB-INF/classes). And it´s free. I´ve been using it for a couple of years. I think myeclipseide bundles the same plugin, but I´m not sure.

Posted by Martin Paoletta on November 08, 2005 at 02:12 AM MST #

Err.. in IDEA i rarely redeploy (actually restart the Tomcat). i create the classes directly in the WEB-INF/classes and that's it. i do not know what is the fuss about..

Posted by afsina on November 08, 2005 at 03:54 AM MST #

anyone tried Eclipse Webtools? http://www.eclipse.org/webtools seems to be quite good.

Posted by James on November 08, 2005 at 04:52 AM MST #

Matt, I just bit the bullet about two months ago and restructured my appfuse/struts-resume based application so it would work directly in Eclipse without having to re-deploy. Here are the basics.
  • Yes, I use the Sysdeo plug-in. Later I want to play with the Eclipse Web Tools project a bit more as it seems to have a decent JSP editor that does not have the overhead of something like NitroX. For now its Sysdeo though.
  • The build is broken into these steps:
    1. xdoclet generation, output is into directory "src-gen". I do a lot of this.
    2. compile Java files into "web/WEB-INF/classes".
    3. copy generated/manipulated configuration files under "web/WEB-INF"
  • The above three steps take right at a minute - from this point on, I can use the Eclipse debugger and make changes to my Java files on the fly.
  • The only files under the "/web" subdirectory (including "WEB-INF", ...) are files that are hand-coded and not modified by xdoclet
  • Obviously deployment descriptors generated by ant/xdoclet have to be copied under "web/WEB-INF".
  • Obviously my "clean" target has to clean out anything I moved under "web".
  • And I have a slightly third step above that I do so I can build a war file for production deployment.
I keep saying "What too me so long to do this?"

Posted by Richard on November 08, 2005 at 06:40 AM MST #

I've had good success with IDEA 4 and 5. It supports several project models, but the most natural one pretty common: <project-root>/ src/ web/ which builds to: exploded/ The File -> New Web Module project just sort of falls into this structure. When you make changes, it does a decent job of redeploy, but it's also possible to undeploy and deploy a webapp by clicking a button. The same is true of WTP in Eclipse, which supports this project model, various servers, and start / stop / undeploy / deploy. WTP is pretty flexible and has come a long way in stabilty over the last few months -- should be totally usable for web applications.

Posted by Eddie O'Neil on November 08, 2005 at 06:45 AM MST #

I used to have a separate exploded directory for my web app in IDEA, and had to wait forever for idea to copy files on it even when it wasn't needed: it seems IDEA has a hard time scanning the destination directory. Since then I moved to an "in place" (i.e.: no exploded directory) editing mode, and my builds/deploys are running a little bit faster (although IDEA still takes a long time apparently scanning all of my webapp structure when starting the debug). I use hot-reload of classes, and it works pretty well, when I have already set up the major layout of my class hierarchy and don't have to do "schema changes".

Posted by Davide Baroncelli on November 08, 2005 at 08:11 AM MST #

Matt, I think it would be wonderfull if you modified Appfuse to be Eclipse friendly. I been mostly using Appfuse with JSF and have tried to use it with Eclipse WTP/Exadel pluggins but came accross many issues. In fact, the best way seems to be to generate the project and use the expanded war directory. One of the reasons for this is the validation(web.xml, faces-config.xml, spring files, ...) and since alot of the files are not yet generated, it causes problems. Same thing with the JSP includes files. Exadel also relies on faces-config for autocomplete in JSPs for manage beans. I beleive Appfuse is a great app starter, but I do think it would require alot of tweaking to make it play nice with Eclipse and WTP out of the box.

Posted by Rene Lavoie on November 08, 2005 at 12:13 PM MST #

At my old job, we used WSAD to run an appfuse based application. We did our full development cycle from within WSAD and the embedded WAS instance. It worked great. Check out http://raibledesigns.com/wiki/Wiki.jsp?page=AppFuseWSAD for hints on how to do it. I am currently in the process of making another application run completely from within NetBeans and will update the appfuse Wiki when I am finished.

Posted by Matthew Fleming on November 08, 2005 at 06:27 PM MST #

I extend build.xml with HotSwap task which copies changed classes and web resources to Tomcat dir, compilation now takes about 10-20 seconds.

Posted by Dmitry Kashin on November 17, 2005 at 10:26 AM MST #

We use Eclipse and JettyLauncher in development and Tomcat in ua test/production. Keep the project in exploded war format and start/stop is easy. Debugging in Eclipse with hot swap is a breeze too. Since tomcat is only for "production like" deployments we don't bother interacting with Tomcat from the IDE. Geoff

Posted by Geoff Longman on November 25, 2005 at 03:45 PM MST #

Hi Richard, please let me know in greater detail how you configured the appfuse app with the exploded war format and the changes u made to the provided ant build script (from matt). best wishes

Posted by Richard on December 17, 2005 at 09:29 PM MST #

Hi, I would like to know how to setup WTP and appfuse, has any body seen a good reference on the web? Regards

Posted by Samuel Velázquez on April 06, 2006 at 10:51 PM MDT #

Richard,

Sorry, but somehow I missed your Dec 17th post so did not respond. But still, I believe the details really are in my original post. Consdier that I took a snapshot of appfuse (actually Struts Resume at the time) in January 2003, re-synched it with many of the improvement in AppFuse in summer 2005. During and since them I have modified it as my application grew and evolved. But the steps above are a pretty good guideline. It has completely changed my mind about the usefulness of IDE's for anyone but a newbie.

Also, I am now using Sysdeo with the all-in-one WTP Eclipse bundle now. The editors that come with WTP for Javascript, CSS, HTML, JSP, etc - may not be the absolute best, but they are all there. I have hesitated to use WTP's servers in place of Sysdeo's because of horrible performance stories I have heard. I'll try it for myself one of these days.

Good luck - Richard

Posted by Richard on April 06, 2006 at 11:59 PM MDT #

Samuel: have yoy figured out how to setup WTP with appFuse?. This is my first time with eclipse so I'm kind of lost. Help is appreciated

Posted by Roni Burd on April 10, 2006 at 11:05 PM MDT #

Dare I say it... Try NetBeans. It has a built-in Tomcat 5.5 server, auto-deploy, and is very flexible about where your source and config files live and how those files get packaged together for deployment. If you're trying to support the standard opensource project layout (src, lib, conf, build) then NetBeans will be your friend. And, for that matter, if you need to retain compatibility with your existing ANT script that's directly supported as well. Although I'd probably recommend you let NetBeans run off it's own auto-generated and auto-maintained ant scripts and use the provided Ant hooks to do further customization. And there's direct support in Netbeans for a separate test build. Meaning you can easily specifiy a different set of test libraries for both test-compilation and test-running. This lets you keep those libs easily separate from your apps normal libs if you so choose. There are not very many places where Netbeans is better than Eclipse, IMO, but webapp development, is one of them.

Posted by Gary Affonso on May 17, 2006 at 05:47 AM MDT #

Hi ,
We use an ant task to hotswap only changed classes. The main trick is , do it with the JDI(Java Debagging Interface). You have to start your jvm in debugging mode and through it, you can hotswap only changed classes. Since it works on port, you can do this on remote machines also. The IDE (eclipse/netbeans/IDEA) do it the same way. But I prefer ANT for the deployment.

Here is the details about it in my blogpost

Posted by Sajid on July 29, 2008 at 05:31 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed