【发布时间】:2013-08-06 22:53:33
【问题描述】:
我有一个基于 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文件中检查过,存在两个名称不同的MyAppDomain jars ??
-
是的,他们都在那里。请参阅下面的解决方法。
标签: java maven tomcat intellij-idea