Intellij多模块maven项目,其中一个子模块中的更新不会传播到战争中 [英] Intellij multi-module maven project, update in one of the submodules is not propogated to war

查看:155
本文介绍了Intellij多模块maven项目,其中一个子模块中的更新不会传播到战争中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Intellij Idea 12并拥有一个多模块maven项目。

I'm using Intellij Idea 12 and have a multi module maven project.

为了简单起见,我们假设我有:

To make it simple let's assume that I have:


  • 模块A - 编译为JAR

  • 模块B - 取决于模块A并且还编译为JAR

  • 模块C - 取决于模块B,但编译为WAR

我知道Intellij有自己的maven构建机制因此,当我第一次构建WAR并将其部署到Tomcat时,通常都可以正常工作。当您需要在其中一个子模块中进行更改时,问题就开始了,例如模块A并重建战争(重建模块C)

I know Intellij has it's own build mechanism for maven projects so when I build a WAR for the first time and deploy it to Tomcat generally all works as it should. The problem start when you need to make changes in one of the sub modules, for example Module A and rebuild the War (rebuild Module C)

Intellij,因为它似乎使用了旧模块以前构建的jar,忽略了我在创建/构建模块C时在模块A中所做的任何更改。

Intellij as it seems uses the old Module A jar that was previously build and ignores any changes I made in Module A when making/building Module C.

我找到解决此问题的唯一方法是运行模块A和B上的Maven构建并最初使用Maven构建WAR并将其部署为外部源。

The only way I found to solve this is to run a Maven build on Module A and B and initiallly build the WAR with Maven and deploy it as external source.

问题是我有10个WAR要部署和超过20个子模块编译成罐子。当我只想看到我在一个影响一个WAR的子模块中所做的更改时,重建所有战争是没有意义的。在支付Intellij Ultimate许可证的同时使用命令行在外部构建它们是没有意义的(所以我可以使用应用程序服务器)

The problem is that I have 10 WARs I want to deploy and more then 20 sub modules that compiled to jars. It doesn't make sense to rebuild all wars when I'm only want to see the changes I made in one of sub modules that affects one WAR. And sure doesn't make sense to build them externally with command line while paying for Intellij Ultimate license (so I can work with Application servers)

现在将此行为与其他行为进行比较IDE
1. Netbeans自然地通过Maven和所有构建/部署与maven项目一起工作,这些都是通过Maven完成的,而不是通过某种内部机制完成的。
2. Eclipse使用它的内部机制做同样的事情,但是在重建WAR项目时会更新所有JAR。 (或其他一些有效的魔法)

Now comparing this behavior to other IDE 1. Netbeans works with maven projects naturally via Maven and all builds/deployments and such are done with Maven and not by some internal mechanism. 2. Eclipse does the same with it's internal mechanism but all JARs are updated when WAR project are rebuild. (Or some other magic that works)

有没有一种方法可以与IDEA区别对待或者没有?

Is there a way work differently with IDEA or there isn't ?

推荐答案

最终我找到了一个混合解决方案:
Tomcat运行之前要做的事情:

Eventually I found a hybrid solution for this: Things to be done before Tomcat is run:


  1. 全部清理

  2. 构建,打包和注册(在存储库中)应该成为JAR的所有项目

  3. 仅编译(Don'构建)WAR项目

  4. 使用Intellij构建WAR工件(这是热插拔可用性所必需的)

  1. Clean all
  2. Build, package and register (in repository) all projects that should become JAR
  3. Compile only (Don't build) WAR projects
  4. Build WAR artifacts with Intellij (This is needed for hot swap availability)

这就是我启动Tomcat的方式。

This is how I start Tomcat.

详细信息:


  1. 创建3个Maven运行配置

  1. Create 3 Maven run configurations

1.1 清理所有项目
1.2 构建所有带有JAR工件的项目。您需要使用'-pl'maven选项手动包含所有项目。您可以选择在启动此配置之前运行Maven clean(查看屏幕截图)
1.3 编译所有带有WAR工件的项目 - 不使用Maven打包

1.1 Clean all projects 1.2 Build all projects with JAR artifacts. You need to manually include all your projects with the '-pl' maven option. Optionally you can run "Maven clean" before launch of this configuration (look at screenshot) 1.3 Compile all Projects with WAR artifacts - No packaging with Maven

创建Tomcat配置以构建War工件并包含在Launch

Create Tomcat configuration to Build War artifacts and include other configurations to run before Launch

现在运行Tomcat时可以热交换代码更改(如果JVM允许)或只是重新启动服务器以包含所有新代码/更改。这样做的缺点是Tomcat的启动时间稍长。这是我们愿意忍受的......现在

Now when Tomcat is run it is possible to hotswap code changes (if JVM allows) or simply restart server to include all your new code/changes. The draw back of this is somewhat longer start time of Tomcat. That's something we are willing to live with..... For now

这篇关于Intellij多模块maven项目,其中一个子模块中的更新不会传播到战争中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆