我有一个具有以下结构的多模块 Maven 项目:
app (parent)
-- pom.xml
-- app-ear
-- pom.xml
-- app-ejb
-- src
-- pom.xml
-- app-web
-- src
-- pom.xml
应用程序/pom.xml
这是我的app/pom.xml(父项目),我在其中放置了所有应用程序依赖项:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>app</name>
<url>http://maven.apache.org</url>
<modules>
<module>app-ejb</module>
<module>app-web</module>
<module>app-ear</module>
</modules>
<dependencies>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javaee</groupId>
<artifactId>javaee-api</artifactId>
<version>5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.0.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-bom</artifactId>
<version>4.2.0.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
应用程序-ejb/pom.xml
这是我的app-ejb/pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>app</artifactId>
<groupId>com.mycompany</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>app-ejb</artifactId>
<packaging>ejb</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
这是我的app-web/pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>app</artifactId>
<groupId>com.mycompany</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>app-web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>app-ejb</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>app-web</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
</project>
app-ear/pom.xml
最后,这是我的app-ear/pom.xml,其中我有关于如何生成我的 app.ear 文件的详细信息:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>app</artifactId>
<groupId>com.mycompany</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>app-ear</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>app-ejb</artifactId>
<type>ejb</type>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>app-web</artifactId>
<type>war</type>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>app</finalName>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.7</version>
<configuration>
<version>5</version>
<unpackTypes>war</unpackTypes>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<skinnyWars>true</skinnyWars>
<modules>
<webModule>
<groupId>com.mycompany</groupId>
<artifactId>app-web</artifactId>
<bundleFileName>app-web.war</bundleFileName>
<contextRoot>/app</contextRoot>
</webModule>
<ejbModule>
<groupId>com.mycompany</groupId>
<artifactId>app-ejb</artifactId>
<bundleFileName>app-ejb.jar</bundleFileName>
</ejbModule>
<jarModule>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
</jarModule>
<jarModule>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-api</artifactId>
</jarModule>
<jarModule>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
</jarModule>
<jarModule>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-api</artifactId>
</jarModule>
<jarModule>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
</jarModule>
<jarModule>
<groupId>net.sourceforge.cssparser</groupId>
<artifactId>cssparser</artifactId>
</jarModule>
<jarModule>
<groupId>org.w3c.css</groupId>
<artifactId>sac</artifactId>
</jarModule>
<jarModule>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
我的问题是app.ear/app-web.war!META-INF/MANIFEST.MF和app.ear/app-ejb.jar!META-INF/MANIFEST.MF看起来像这样:
Manifest-Version: 1.0
Build-Jdk: 1.6.0_24
Class-Path: lib/javax.faces-2.0.9.jar lib/richfaces-core-api-4.2.0.Fin
al.jar lib/richfaces-core-impl-4.2.0.Final.jar lib/richfaces-componen
ts-api-4.2.0.Final.jar lib/richfaces-components-ui-4.2.0.Final.jar li
b/cssparser-0.9.5.jar lib/sac-1.3.jar lib/guava-10.0.1.jar lib/jsr305
-1.3.9.jar
Created-By: Apache Maven
Archiver-Version: Plexus Archiver
而且我真的必须从这些清单中删除 Class-Path 条目。
为什么?因为似乎 RichFaces 在我的应用程序的类路径中被加载了两次。(一个来自 app.ear/lib 文件夹,另一个来自 app.ear/app-web.war!META-INF/MANIFEST.MF 类路径条目)。当我尝试在我的应用程序服务器(Oracle Weblogic 10.3.5)中部署 app.ear 时,我得到了一些类似的错误:
INFO: Unsanitized stacktrace from failed start...
java.lang.IllegalArgumentException: duplicate key: class javax.faces.validator.RequiredValidator
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:115)
at com.google.common.collect.RegularImmutableMap.<init>(RegularImmutableMap.java:72)
at com.google.common.collect.ImmutableMap$Builder.fromEntryList(ImmutableMap.java:221)
at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:207)
at org.richfaces.javascript.ClientServiceConfigParser.parseConfig(ClientServiceConfigParser.java:53)
at org.richfaces.application.ValidatorModule.createClientScriptService(ValidatorModule.java:65)
at org.richfaces.application.ValidatorModule.configure(ValidatorModule.java:60)
at org.richfaces.application.ServicesFactoryImpl.init(ServicesFactoryImpl.java:27)
奇怪的是,如果我mvn package
在我的app-web项目中运行,Class-path 条目不会转到 app-web.war/META-INF/MANIFEST.MF。它仅在我mvn package
在我的应用父项目中运行时发生。
那么,如何删除 webModule 和 ejbModule MANIFEST 文件的 Class-path 条目?
我在这个线程中发现了类似的问题,但没有解决方案。
我很感激任何帮助。
谢谢,毛里西奥