Maven 还不值得用于 EAR 部署吗?
我正在将几个 J2EE 项目从 Ant 移植到 Maven2。所有这些项目都包含 1 个 EJB 和 1 个 Web 模块,并使用推荐的“瘦身”EAR 打包方法。这意味着 EJB 和/或 Web 模块依赖的 JAR 都只是放在 EAR 的根目录中。 EJB 和 Web 模块在各自的清单中都有 Class-Path 条目来引用特定的 JAR,而且 Web 模块 Class-Path 还将引用 EJB jar。
我很震惊(是不是太强了?:))发现 Maven 对此支持不是很好。我阅读了有关处理瘦 WAR 的官方页面,但这意味着我必须在 EAR pom 中复制 WAR 依赖项,更糟糕的是,还要复制传递依赖项。如果您必须在任何地方手动处理依赖关系,那么采用 Maven 似乎毫无意义!
然后我开始谷歌搜索并找到了各种解决方法 - 显然,我不是第一个 (a) 想要做一个精简的 EAR 和 (b) 不喜欢 Maven 建议的方法(这本身就是一种解决方法)的人。
我尝试了其中一些方法,但没有一个对我有用。我还发现了一些看起来像 Maven bug 的问题,例如 WAR 插件“packagingExcludes”指令仅排除直接依赖项,而不排除任何传递性依赖项!不太有信心。我发现了这个特定问题的 JIRA 问题,但它仍然处于开放状态。
然后我发现我的命令行 Maven 2.2.1 的行为与我的 m2eclipse 嵌入式 Maven (Embedder v. 3.0) 不同。我们的开发人员肯定希望从 Eclipse 驱动 Maven,因此依赖最新的命令行版本不是一个选择。
所以,我的问题是:现在以及在可预见的未来,如果我们在 Eclipse 中进行所有开发并且主要在瘦小的 EAR 项目上工作,是否值得迁移到 Maven? Maven 的未来是否有任何东西可以使其以更健壮和集成的方式处理 EAR?
I'm in the process of porting several J2EE projects from Ant to Maven2. All of these projects contain 1 EJB and 1 web module, and use the recommended "skinny" EAR packaging method. This means that the JARs that the EJB and/or web modules depend on are all just put in the root of the EAR. Both EJB and web modules have Class-Path entries in their respective manifests to reference the specific JARs, plus the web module Class-Path will also reference the EJB jar.
I was horrified (is that too strong? :)) to find that Maven doesn't support this very well. I read the official page on handling skinny WARs, but that meant I had to duplicate the WAR dependencies in the EAR pom and, even worse, also the transitive dependencies. It seems pointless to adopt Maven if you have to manually handle dependencies anywhere!
I then starting Googling and found a variety of workarounds - obviously, I'm not the first person to (a) want to do a skinny EAR and (b) don't like the Maven suggested approach (which is itself a workaround).
I tried some of these approaches, but none of them worked for me. I also found some issues that looked like Maven bugs, e.g. the WAR plugin 'packagingExcludes' directive excludes only the direct dependencies, not any transitive ones! Not very confidence inspiring. I found a JIRA issue for this specific one, but it's still open.
I then found that my command-line Maven 2.2.1 does things differently to my m2eclipse embedded Maven (Embedder v. 3.0). Our developers would definitely want to drive Maven from Eclipse, so relying on the latest command-line version was not an option.
So, my question is: right now, and for the forseeable future, is it worth migrating to Maven if we do all our development in Eclipse, and work mostly on skinny EAR projects? Is there anything in Maven's future that would make it handle EARs in a more robust and integrated way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短的故事:不,在 M2Eclipse 仍然损坏的情况下不会。
长话短说:
目前,我建议不要这样做,至少在 Eclipse 中是这样。在撰写本文时,M2Eclipse 插件一直存在一个非常令人讨厌的错误,即它生成自己版本的 application.xml 描述符文件,而不是使用 Maven 本来创建的版本。
不幸的是,这个自定义创建的 application.xml 是完全错误的:它忽略了 FinalNames,有一个明显硬编码的“lib/”前缀,并出于某种原因为 EJB JAR 分配了扩展名“.ejb”。更糟糕的是,您无法删除它以替换为 Maven 的版本,因为它不断被 M2Eclipse 重新生成。
如果 application.xml 尚未就位,Maven 只会生成它。由于 WTP/M2Eclipse 生成的 application.xml 不断重新生成,因此 Maven application.xml 没有机会。
不过,这个问题有一个解决方法:你可以告诉 Maven 在打包过程中忽略 application.xml,这样它就会认为 application.xml 不存在,在这种情况下它仍然会生成自己的版本。这样,错误生成的 application.xml 文件就无关紧要了。供将来参考:
但一个主要问题是,用于部署到 Eclipse 中的 GlassFish 的 Ant 脚本会生成自己单独的 EAR 进行部署,并使用 M2Eclipse 生成的 application.xml 来执行此操作。这意味着只要 M2Eclipse 插件仍然损坏,它生成的 EAR 就总是错误的。 codehaus JIRA 上有关于此问题的错误报告,但现在无法访问它们。
对于其他应用程序服务器来说是 YMMV,但要做好大量摆弄 application.xml 的准备。
Short story: No, not while M2Eclipse remains broken.
Long story:
Currently, I would recommend against it, at least in Eclipse. At the time of writing the M2Eclipse plugin has and always has had a very nasty bug where it generates its own version of the application.xml descriptor file rather than use the one Maven would otherwise create.
Unfortunately, this custom-created application.xml is downright wrong: it ignores finalNames, has an apparently hardcoded "lib/" prefix and assigns EJB JARs the extension ".ejb" for some reason. What's worse, you cannot remove it to be replaced with Maven's version as it keeps getting regenerated by M2Eclipse.
Maven will only generate application.xml if it's not already in place. Because the WTP/M2Eclipse-generated application.xml keeps getting regenerated, the Maven application.xml doesn't get a chance.
There is a workaround for this problem, however: you can tell Maven to ignore the application.xml during packaging so that it thinks application.xml is not there, in which case it will still generate its own version. That way, the wrongly-generated application.xml file wouldn't matter. For future reference:
One major problem though is that the Ant script used for deployment to GlassFish in Eclipse generates its own separate EAR for deployment, and uses the M2Eclipse-generated application.xml for doing so. That means the EARs it generates will always be wrong as long as the M2Eclipse plugin remains broken. There are bug reports for this on the codehaus JIRA, can't access them right now though.
YMMV for other application servers, but be prepared for heavy fiddling with application.xml.
你真的确定这是 m2eclipse 做的吗?我正在使用 JBoss Tools 3.1,其中包括 m2eclipse 集成,并准确地解决您所说的问题。但是,我不认为 m2eclipse 根本不关心源 application.xml 的理由。
我怀疑 JBoss Tools 将信息注入到 application.xml 中。请证明我错了,我将永远停止使用 m2eclipse 因为它改变了 /target 下以外的任何内容。
//GG
Are you really sure it's m2eclipse doing this? I'm using JBoss Tools 3.1 which includes m2eclipse integration and get exactly the problem you're stating. However, I don't see the rationale for m2eclipse to care at all about the source application.xml.
My suspicion is that JBoss Tools injects information into the application.xml. Please prove I'm wrong, I'd stop using m2eclipse forever fi it changed anything that's not under /target.
//GG
确实,Maven 不支持 skinny WARs (另请参阅 解决 Skinny Wars 问题 wiki 页面)非常好,因为这从一开始就没有计划,并且 Maven 假设胖 WAR。因此,构建瘦 WAR 和瘦 EAR 的方法实际上更多的是构建在现有插件之上的解决方法。是的,这很容易出错。
请注意,您可以将 m2eclipse 配置为使用外部 Maven,而不是嵌入式 Maven。这实际上就是我所做的,我想要与 CI 引擎使用的版本完全相同的版本。
我的建议很简单:如果 Maven 不支持您想要构建软件的方式(合法与否,这不是问题),就不要使用它。
Indeed, Maven doesn't support skinny WARs (see also the Solving the Skinny Wars problem wiki page) very well because this was just not planned from the start and Maven assumes fat WARs. So the way to build skinny WARs and skinny EARs is indeed more a workarounds built on top of existing plugins. And, yes, this is error prone.
Note that you can configure m2eclipse to use an external Maven instead of the embedded Maven. This is actually what I do, I want exactly the same version that the CI engine uses.
My advice is simple: if Maven doesn't support the way you want to build software (legitimate or not, that's not the question), don't use it.