开发者

Maven + Tomcat acceleration

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.


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.


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.


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 Java EE 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜