3

我一直在使用 Maven EAR 插件为一个新项目创建我的 ear 文件。我在插件文档中注意到您可以为模块指定排除语句。例如我的插件的配置如下...

  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.4.1</version>
        <configuration>
            <jboss>
                <version>5</version>
            </jboss>
            <modules>
                <!-- Include the templatecontroller.jar inside the ear -->
                    <jarModule>
                        <groupId>com.kewill.kdm</groupId>
                        <artifactId>templatecontroller</artifactId>
                        <bundleFileName>templatecontroller.jar</bundleFileName>
                        <includeInApplicationXml>true</includeInApplicationXml>
                    </jarModule>
                    <!-- Exclude the following classes from the ear -->
                    <jarModule>
                       <groupId>javax.activation</groupId>
                       <artifactId>activation</artifactId>
                       <excluded>true</excluded>
                    </jarModule>
                    <jarModule>
                   <groupId>antlr</groupId>
                   <artifactId>antlr</artifactId>
                   <excluded>true</excluded>
                </jarModule>
                ... declare multiple excludes
                <security>
                    <security-role id="SecurityRole_1234">
                        <role-name>admin</role-name>
                    </security-role>
                </security>
            </configuration>
        </plugin>
    </plugins>

对于需要排除 4-5 个模块的小型项目,这种方法绝对适用。但是,在我的项目中,我有 30 多个,而且我们才刚刚开始该项目,因此随着它的扩展,这可能会增长。

除了显式声明每个模块的排除语句之外,是否可以使用通配符或排除所有 Maven 依赖项标志以仅包含我声明的那些模块并排除其他所有内容?有人知道更优雅的解决方案吗?

4

3 回答 3

1

不确定是否支持通配符,但编写自己的 mojo 非常简单。您可以包装现有的 mojo,然后采用您自己设计的一些任意配置,例如您的通配符语法。

更好的是,您可以将您的 mojo 提交给 maven 团队(!)

于 2010-03-16T09:33:49.587 回答
1

除了明确声明每个模块的排除语句之外,是否可以使用通配符或排除所有 Maven 依赖项标志以仅包含我声明的那些模块并排除其他所有内容?

maven-ear-plugin不提供开箱即用的此功能(而且我认为无论如何配置都不容易,必须非常精确地打包耳朵)。但是,这里不清楚的是如何获得需要排除的依赖项。根据您的回答,可能有几种方法可以处理它们:

  • 如果它们是您的工件的依赖项,您可以将其中一些声明为可选,以避免传递地检索它们。
  • 您可以将一些依赖项标记为“已提供”(并将它们放在父 pom 中,仅在 EAR 的 POM 中重新声明您想要的内容)。

很难在没有看到全貌的情况下回答。

于 2010-03-16T22:16:47.697 回答
0

我面临着类似的问题。但那是因为我有一个多模块项目,其中有几个 jar 具有提供的范围,我只是从子耳 pom 中删除了父标签,使其独立。然后使用 include 包含我需要的尽可能多的罐子。

希望这可以帮助!!!

于 2013-09-19T08:37:14.860 回答