Maven + Tomcat hot deploy

2019-04-12 05:06发布

问题:

I've searched on the internet for this question and found no single solution. We have a maven project that uses profiles to build artifact that suits dev/qa/prod environtments, does minification of JS and CSS using YUI plugin. It uses Spring for dependency injection and struts as UI framework. Ibatis is used as ORM mapper. We use Eclipse IDE on windows and are not using integrated eclipse as we need to deploy Unix servers. Now, my question is, is there a way to deploy this solution in such a way that changes to js, css, jsp, applicationContext files of spring, struts.xml, ibatis mapper files and of course Java code to take immediate effect without server restart. I remember spring-groovy plugin supports reload of context for a change in groovy file. So, I presume there should be a way supports hot deploy too.

回答1:

I find that maven tomcat plugin is slow because it always use the tomcat's client deployer and deploys by the http calls on the manager like localhost:8080/manager/text

Tomcat has a web application reloading mechanism managed by "autoDeploy" that you can read about it here. So being that it reloads whenever the application war is changed I have made the following change to my maven-war-plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <outputDirectory>${my.tomcat.path}</outputDirectory>
    </configuration>
</plugin>

where

<properties>
    <my.tomcat.path>[MY TOMCAT WEBAPP PATH]</my.tomcat.path>
</properties>

After this I only need to do mvn compile war:war or mvn compile package



回答2:

You can try the maven tomcat plugin - specifically the tomcat:run goal. You can also configure maven eclipse plugin to create a dynamic web project and then deploy from within eclipse.



回答3:

That sounds to me like JRebel. (sorry for the commercial).



回答4:

Maven integration with Netbeans does this for you. Just File->Open your project, click Run (which deploys and spawns a web browser for testing), then modify your code in the IDE and each time you click save it will hot deploy changes.