java Maven + Tomcat 热部署

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7749500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:15:17  来源:igfitidea点击:

Maven + Tomcat hot deploy

javaspringmaventomcat6

提问by Gopal

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.

我在互联网上搜索了这个问题,但没有找到单一的解决方案。我们有一个 maven 项目,它使用配置文件构建适合 dev/qa/prod 环境的工件,使用 YUI 插件缩小 JS 和 CSS。它使用 Spring 进行依赖注入,使用 struts 作为 UI 框架。Ibatis 用作 ORM 映射器。我们在 Windows 上使用 Eclipse IDE 而没有使用集成的 Eclipse,因为我们需要部署 Unix 服务器。现在,我的问题是,有没有一种方法可以部署此解决方案,即更改 js、css、jsp、spring 的 applicationContext 文件、struts.xml、ibatis 映射器文件以及 Java 代码,无需服务器即可立即生效重新开始。我记得 spring-groovy 插件支持重新加载上下文以更改 groovy 文件。所以,我认为也应该有一种支持热部署的方法。

回答by CaughtOnNet

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

我发现 maven tomcat 插件很慢,因为它总是使用 tomcat 的客户端部署器并通过管理器上的 http 调用进行部署,如 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:

Tomcat 具有由“autoDeploy”管理的 Web 应用程序重新加载机制,您可以在此处阅读有关它的信息。因此,每当应用程序War更改时它都会重新加载,因此我对我的 进行了以下更改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:waror mvn compile package

在此之后我只需要做mvn compile war:warmvn compile package

回答by gkamal

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

您可以尝试maven tomcat 插件- 特别是tomcat:run目标。您还可以配置 maven eclipse 插件来创建动态 Web 项目,然后从 eclipse 中进行部署。

回答by khmarbaise

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

这听起来像JRebel。(对不起,商业广告)。

回答by Leif Gruenwoldt

Maven integration with Netbeans does this for you. Just File->Openyour 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.

Maven 与 Netbeans 的集成为您完成了这项工作。只需文件->打开您的项目,单击运行(它会部署并生成用于测试的 Web 浏览器),然后在 IDE 中修改您的代码,每次单击保存时,它都会热部署更改。