Maven-ear-plugin - 排除多个模块,即 jar、wars 等
我一直在使用 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 依赖项标志以仅包含我声明的模块并排除其他所有内容?有人知道更优雅的解决方案吗?
I've been using the Maven EAR plugin for creating my ear files for a new project. I noticed in the plugin documentation you can specify exclude statements for modules. For example the configuration for my plugin is as follows...
<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>
This approach is absolutely fine with small projects where you have say 4-5 modules to exclude. However, in my project I have 30+ and we've only just started the project so as it expands this is likely to grow.
Besides explicitly declaring exclude statements per module is it possible to use wildcards or and exclude all maven dependencies flag to only include those modules i declare and exclude everything else? Is anyone aware of a more elegant solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
maven-ear-plugin 不会不提供开箱即用的此功能(而且我认为配置起来并不容易,耳朵必须非常精确地包装)。但是,这里不清楚的是如何获取需要排除的依赖项。根据您的答案,可能有多种方法来处理它们:
但在没有看到全貌的情况下很难回答。
The maven-ear-plugin doesn't provide this feature out-of-box (and I don't think that it would be easy to configure anyway, an ear must be packaged very precisely). However, what's not clear here is how you get the dependencies you need to exclude. Depending on your answer, there could be several ways to handle them:
Hard to answer without seeing the whole picture though.
不确定是否支持通配符,但编写自己的 mojo 非常简单。您可以包装现有的 mojo,然后采用您自己设计的一些任意配置,例如通配符语法。
更好的是,您可以将您的魔力提交给 Maven 团队(!)
Not sure about whether wildcards are supported, but it is very simple to write your own mojo. You could wrap the existing mojo and then take some arbitrary config of your own design, such as your wildcard syntax.
Better still, you could submit your mojo to the maven team (!)
我面临着类似的问题。但那是因为我有一个多模块项目,其中有几个具有所提供范围的罐子,我刚刚从子ear pom中删除了父标签,从而使其独立。然后使用 include 包含我需要的尽可能多的罐子。
希望这有帮助!
i was facing a similar problem. but that was because i had a multi module project with several jars having the provided scope , i just removed the parent tag from the child ear pom , there by making it independent . and then using include to include as many jars i need.
hope this helps!!!