views:

263

answers:

5

I am writing a web application with Maven in the Eclipse IDE, and use Tomcat servlet container.

So, I run Maven like this: mvn clean compile. It is reasonable that after this operation I must re-run Tomcat so it can reinitialize the context (Sysdeo Tomcat launcher helps a lot).

The problem is Maven execution and subsequent Tomcat re-running takes noticable amount of time (like 10+ seconds for Maven and 20+ sec. for Tomcat, because of logging, O/R mappings, etc.) every time I do it.

Is there any automated and more faster solution for these operations? As I see it, a way better solution can be moving re-compiled classes only to the target dir.

+3  A: 

Maven does two things: Dependency handling and build management. I usually find Maven's dependency management a big time-wasting annoyance that I usually don't need, so I do my build management with ant.

At the price of a hand-tuned build file, ant gives you very good control over which files go where when. If you copy newly compiled classes to your WEB-INF/classes directory and touch web.xml to trigger a reload, you don't have to stop and restart Tomcat. This brings my compile/reload time down to around one second.

This is how I prefer to work. Some Maven fans will disagree violently.


EDIT: That said, there's another method that allows me to skirt the build issue completely: I develop in Eclipse using the WTP functionality that's included with the JEE developer's edition. When I make a code change, I simply hit Ctrl-S to save the changed file and Eclipse automatically copies the newly compiled class into the running Tomcat, so I can then immediately refresh my browser and see the newly changed Web app running. Thanks to Eclipse's incremental compilation, this method probably is probably unbeatable in terms of edit/run cycle time. Of course if you really need Maven then this is not an alternative.

Carl Smotricz
Ridiculous tentative :) Maven doesn't force you more than Ant to restart anything.
Pascal Thivent
Hehe, I was wondering when you'd show up! You're drawn to Maven advocacy like a bear to honey ;)
Carl Smotricz
LOL! I knew it!
Pascal Thivent
Que veux-tu dire avec "tentative?" I suspect that word doesn't mean exactly what you think.
Carl Smotricz
Doh! False friends. What I meant was "attempt", *tentative* in French. Learned something new, thanks.
Pascal Thivent
+1 for the WTP by the way. A typical development workflow is to use the WTP under Eclipse (that Maven support either with the maven-eclipse-plugin or with m2eclipse) and to run Maven before to commit (to verify that the changes won't break the continuous build).
Pascal Thivent
+4  A: 

Is there any automated and more faster solution for these operations? As I see it, a way better solution can be moving re-compiled classes only to the target dir.

Well, the question is why do you run clean each time? Doing incremental compilation would already speed up things a lot.

Update: I agree with @Carl about Eclipse WTP that provides very good support of Tomcat (I don't really see the added value of the Sysdeo plugin nowadays). Using Eclipse WTP for development and running Maven before to commit the changes to check that you didn't break the continuous build is a very typical workflow. And both the maven-eclipse-plugin and m2eclipse (the two alternatives for Maven and Eclipse integration) support the WTP i.e. can get your project recognized as a dynamic project than can be Run on a Server.

Pascal Thivent
Good point about the `clean`, that probably wastes a good bit of re-compilation time.
Carl Smotricz
Agreed, using `clean` is a thoughtless practice in this case. Thank you.
Bar
A: 

There is Maven tomcat plugin can help you, you just execute "mvn tomcat:redeploy", and maven compile the source, package it and deploy it to your configured tomcat, see tomcat plugin for more information.

khotyn
+2  A: 

You may want to have a look at JRebel. It reloads your classes in a running tomcat, so your changes are near instantaneous. I haven't used it much, but it appears to solicit good comments.

Dominic Mitchell
Or just install Glassfish v3 and you won't need JRebel :)
Pascal Thivent
A: 

Eventually, I've solved that by using Eclipse feature called «Build Automatically» (Project → Build Automatically checkbox).
Every time you save a resource, Eclipse compiles it and moves .class file to the output folder.

Bar