Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hot code deploy tomcat with Maven

Tags:

maven

tomcat

I have a web application built using maven. It is built in the form of different projects, that depend on each other - domain, dao, services etc. I ran eclipse:eclipse in each of them to configure my eclipse environment. So now I have multiple projects in eclipse. This is my development environement.

I also built a tomcat bundle for the Operations guys so I can just provide them with a zip file which they can extract and run a batch file to start the server up. This zip file contains a war file which is referred to in the <context> configuration for tomcat.

Also, for development purposes, I have set tomcat to start up from within eclipse. My aim is to do hot code deploy whenever the source changes. This doesnt happen currently because the class files live in the "target" folder(due to maven's directory structure). And tomcat looks at the war file(exploded structure i mean..)

How can i configure my tomcat/eclipse enviroment so I can start doing hot code deploy?

-thanks!

like image 329
Mak Avatar asked Dec 27 '10 21:12

Mak


2 Answers

I use the tomcat-maven-plugin and its goal tomcat7:run to start tomcat from within eclipse (btw using m2e plugin for eclipse - great tool - available from eclipse market place). Hot code replacement doesn't work for me, too. But I use a workaround: with <contextReloadable>true</contextReloadable> tomcat reloads the application whenever it detects a file change.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <path>/myapp</path>
                <contextReloadable>true</contextReloadable>
            </configuration>
        </plugin>
    </plugins>
</build>
like image 133
rudolfson Avatar answered Sep 23 '22 15:09

rudolfson


Tomcat wont' support hot redeploy by itself, unless your application framework supports class reloading. (Tapestry does, but I don't recommend using Tapestry for other reasons). I'm fairly certain that eclipse:eclipse also doesn't support hot redeploy, so you have two things working against you.

You have two alternatives that I know of... first, switch to using M2Eclipse instead of eclipse:eclipse. You'll have to get rid of your old eclipse:eclipse configuration for this to work. Using m2eclipse will export classes from the eclipse compiler to Tomcat. this avoids the intermediate "mvn clean package" step. Once you get m2eclipse running, you can download JRebel. JRebel will support hot redeploy even if the framework doesn't natively support class reloading.

Good luck!

like image 45
Jonathan S. Fisher Avatar answered Sep 21 '22 15:09

Jonathan S. Fisher