java - Intellij IDEA 包含 Maven 已经包含的其他模块

标签 java maven tomcat intellij-idea

我有一个基于 Maven 的 2 模块 Intellij 项目,其组织方式如下:

MyAppProject
    --->MyAppDomain (builds a JAR)
    --->MyAppWAR (builds a WAR, including the JAR above)

我可以使用 Maven 构建项目,生成的 WAR 包含 MyAppDomain.JAR 作为依赖项:

<dependency>
    <groupId>com.mycompany.myapp</groupId>
    <artifactId>MyAppDomain</artifactId>
    <version>1.0.0</version>
</dependency>

这个 WAR 在 Tomcat 中运行。但是,如果我使用 Intellij Idea Ultimate 的简洁 Tomcat 集成构建它,WAR 将失败并出现此错误(为了便于阅读而格式化):

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': 
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/config/data-context.xml]: 
Invocation of init method failed; nested exception is java.lang.IllegalStateException: 
Conflicting persistence unit definitions for name 'caPersistenceUnit': 
file:/C:/JavaSoftware/apache-tomcat-6.0.32/webapps/MyApplication/WEB-INF/lib/MyAppDomain.jar, file:/C:/JavaSoftware/apache-tomcat-6.0.32/webapps/MyApplication/WEB-INF/lib/MyAppDomain-1.0.0.jar

因此,IDEA 似乎包含了 Maven 指定的 JAR (MyAppDomain-1.0.0.jar) 并且还包含了它自己的包含所有相同文件的 JAR 版本 (MyAppDomain.jar)。

我一直在徒劳地寻找在 Intellij IDEA 中关闭此功能的方法 - 有人知道如何停止此行为(包括共同驻留项目)吗?

最佳答案

我无法找出如何关闭此行为,但我找到了一个可以正确构建 WAR 的解决方法。

  1. Select "Run -> Edit Configurations" from the menu. 
  2. Select your"Tomcat Server" job. 
  3. Click the "Deployment" tab. 
  4. At the bottom, where it says "Before Launch:  Another Configuration,"  delete the "Make" option. 
  5. Click the "+" (plus) sign and select your Maven Build task to add it to the "Before Launch" list.

通过这样做,Intellij 将使用您设置的 Maven 构建任务来创建 WAR,而不是使用它自己的“Make”命令。

关于java - Intellij IDEA 包含 Maven 已经包含的其他模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18091890/

相关文章:

java - Spring Boot firebase admin sdk 设置 - 无法解析符号

tomcat - EC2 上的休眠搜索?

tomcat 7 开启多个进程

java - 如何在 Java 中使用 Selenium WebDriver 打开新选项卡?

java - Websphere 7 与 JSF 2

java - 如何获取使用 XMLStreamWriter 生成的文件的文件大小?

java - 使用带有命令行选项的 maven 跳过单个测试

maven - 如何从本地 Maven 仓库中删除项目 Artifact ?

java - 使用 JMX 监视在 Tomcat 中运行的 J2EE 应用程序

java - 哪个集合最适合存储键值对,但我必须同时搜索键和值