如何在 Maven ear build 中删除库?

How do I eliminate libs in Maven ear build?

我有 3 个项目。第一个读取数据库并为我的 ejbs 创建所有 class 文件。第二个是我的ejbs。第三个是我的 .ear 项目,它应该将第二个项目中的 ejb .jar 打包到 .ear 中。

项目 1 工作正常并且 运行 作为 java 应用程序。

项目 2 工作正常,并且有几个 Maven 运行 配置,一个用于创建客户端 jar,一个用于将这些客户端 jar 部署到 Nexus,一个用于创建将打包到的 ejb .jar部署到服务器的 .ear。

项目 3 是个问题。过去,我只是在 eclipse 中导出了 .ear,而且效果很好。现在我正试图让它与 Maven 一起工作。我基本上已经可以正常工作了,但是它一直包含一堆库文件,而且它正在复制错误的文件。

这是pom

<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.kable.newsstand.kdsejb</groupId>
<artifactId>kds-ejb-ear</artifactId>
<version>1.0.0</version>
<packaging>ear</packaging>

<parent>
    <groupId>com.kable.maven</groupId>
    <artifactId>kable-super-pom</artifactId>
    <version>[0.1,1.0)</version>
</parent>

<dependencies>
    <dependency>
        <groupId>com.kable.newsstand.kdsejb</groupId>
        <artifactId>kds-ejb</artifactId>
        <version>1.1.0-SNAPSHOT</version>
        <type>ejb</type>
    </dependency>
</dependencies>

<build>
    <finalName>kdsejbEar</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.10</version>
            <configuration>
                <earSourceDirectory>EarContent</earSourceDirectory>
                <modules>
                    <ejbModule>
                        <groupId>com.kable.newsstand.kdsejb</groupId>
                        <artifactId>kds-ejb</artifactId>
                        <bundleFileName>kdsSession.jar</bundleFileName>
                    </ejbModule>
                </modules>
                <displayName>kdsejbEar</displayName>
                <generateApplicationXml>true</generateApplicationXml>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

第二个项目有一个 运行 配置,用于创建 ejb .jar 并将其命名为 kdsSession.jar

        <plugin>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <jarName>kdsSession</jarName>
                <outputDirectory>${basedir}</outputDirectory>
                <ejbVersion>3.1</ejbVersion>
                <archive>
                    <manifestEntries>
                        <Dependencies>org.apache.commons.lang3</Dependencies>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

我想在我的 .ear 中使用那个 jar。以下是ear项目的输出。

[INFO] Scanning for projects...
[WARNING] Failed to build parent project for com.kable.newsstand.kdsejb:kds-ejb-ear:ear:1.0.0
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building kds-ejb-ear 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ kds-ejb-ear ---
[INFO] Deleting C:\Users\bray\eclipse-workspaces\kds-ejb\kdsejbEar\target
[INFO] 
[INFO] --- maven-ear-plugin:2.10:generate-application-xml (default-generate-application-xml) @ kds-ejb-ear ---
[WARNING] The POM for org.apache.commons:commons-compress:jar:1.9 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] Generating application.xml
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ kds-ejb-ear ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\bray\eclipse-workspaces\kds-ejb\kdsejbEar\src\main\resources
[INFO] 
[INFO] --- maven-ear-plugin:2.10:ear (default-ear) @ kds-ejb-ear ---
[INFO] Copying artifact [ejb:com.kable.newsstand.kdsejb:kds-ejb:1.1.0-20181024.164321-158] to [kdsSession.jar]
[INFO] Copying artifact [jar:org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec:1.0.2.Final] to [jboss-ejb-api_3.1_spec-1.0.2.Final.jar]
[INFO] Copying artifact [jar:org.jboss.ejb3:jboss-ejb3-ext-api:2.2.0.Final] to [jboss-ejb3-ext-api-2.2.0.Final.jar]
[INFO] Copying artifact [jar:org.hibernate:hibernate-envers:5.1.13.Final] to [hibernate-envers-5.1.13.Final.jar]
[INFO] Copying artifact [jar:org.jboss.logging:jboss-logging:3.3.0.Final] to [jboss-logging-3.3.0.Final.jar]
[INFO] Copying artifact [jar:org.hibernate:hibernate-core:5.1.13.Final] to [hibernate-core-5.1.13.Final.jar]
[INFO] Copying artifact [jar:org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final] to [hibernate-jpa-2.1-api-1.0.0.Final.jar]
[INFO] Copying artifact [jar:org.javassist:javassist:3.20.0-GA] to [javassist-3.20.0-GA.jar]
[INFO] Copying artifact [jar:antlr:antlr:2.7.7] to [antlr-2.7.7.jar]
[INFO] Copying artifact [jar:org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1] to [geronimo-jta_1.1_spec-1.1.1.jar]
[INFO] Copying artifact [jar:org.jboss:jandex:2.0.3.Final] to [jandex-2.0.3.Final.jar]
[INFO] Copying artifact [jar:dom4j:dom4j:1.6.1] to [dom4j-1.6.1.jar]
[INFO] Copying artifact [jar:org.hibernate:hibernate-commons-annotations:3.2.0.Final] to [hibernate-commons-annotations-3.2.0.Final.jar]
[INFO] Copying artifact [jar:org.slf4j:slf4j-api:1.5.8] to [slf4j-api-1.5.8.jar]
[INFO] Copying artifact [jar:org.hibernate:hibernate-entitymanager:5.1.13.Final] to [hibernate-entitymanager-5.1.13.Final.jar]
[INFO] Copying artifact [jar:org.apache.commons:commons-lang3:3.5] to [commons-lang3-3.5.jar]
[INFO] Copy ear sources to C:\Users\bray\eclipse-workspaces\kds-ejb\kdsejbEar\target\kdsejbEar
[INFO] Could not find manifest file: C:\Users\bray\eclipse-workspaces\kds-ejb\kdsejbEar\target\kdsejbEar\META-INF\MANIFEST.MF - Generating one
[INFO] Building jar: C:\Users\bray\eclipse-workspaces\kds-ejb\kdsejbEar\target\kdsejbEar.ear
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:47 min
[INFO] Finished at: 2018-10-25T14:09:10-05:00
[INFO] Final Memory: 17M/332M
[INFO] ------------------------------------------------------------------------

如您所见,它出于某种原因正在复制一些库文件。我不想要那些。它也没有得到预先存在的 kdsSession.jar,而是创建一个新的

我该如何纠正这种行为?

在你耳边的项目运行mvn dependency:tree

查看它并尝试找出不需要的 jar 的来源。

也许您在 kds-ejb 项目中声明了依赖项。 如果是这种情况,请将范围设置为提供。

有关作用域的更多信息,请访问 Introduction to the Dependency Mechanism