maven-ear-plugin - 如何操作webModule和ejbModule的Manifest.MF?

时间:2012-07-09 19:21:46

标签: maven manifest ear manifest.mf maven-ear-plugin

我有一个具有以下结构的多模块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>

应用耳/ 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

我真的必须从这些MANIFEST中删除Class-Path条目。

为什么呢?因为似乎RichFaces在我的应用程序的类路径中被加载了两次。 (一个来自app.ear / lib文件夹,另一个来自app.ear / app-web.war!META-INF / MANIFEST.MF Class-Path条目)。当我尝试在我的Application Server(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)

奇怪的是,如果我在 app-web 项目中运行mvn package,则类路径条目不会转到app-web.war / META-INF / MANIFEST.MF 。只有在我的 app 父项目中运行mvn package时才会出现这种情况。

那么,我怎样才能删除webModule和ejbModule MANIFEST文件的Class-path条目?

我在this thread中发现了类似的问题但没有解决方案。

我感谢任何帮助。

谢谢, 毛

1 个答案:

答案 0 :(得分:3)

您需要在配置标记内的 app-ear / pom.xml 中添加以下条目

<archive>
    <manifest>
        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
    </manifest>
    <manifestEntries>
        <Created-On>${build.timestamp}</Created-On>
        <Ant-Version>${ant.version}</Ant-Version>
        <Java-Version>${ant.java.version}</Java-Version>
    </manifestEntries>
</archive>

通常,设置为false的addDefaultImplementationEntries标记会阻止在清单中写入所有默认条目(例如您想要的条目)。之后,您可以添加任何想要包含的内容。我添加了一些您可以看到的样本。