如何在Eclipse中处理Maven WAR重叠? [英] How to handle Maven WAR overlays in Eclipse?

查看:134
本文介绍了如何在Eclipse中处理Maven WAR重叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多模块的Maven项目,它使用了WAR叠加层(它们的堆栈3深)。一切都在Maven中运行得很好,但是我无法从Eclipse中启动我的WAR,因为它抱怨找不到各种文件。



如何配置Eclipse(和启动器),以便我可以从Eclipse运行我的WAR,而不必首先做Maven安装?我应该补充说,我的Eclipse WAR项目不是动态Web项目...是我需要做的一部分?



注意:以下问题涉及主题,但答案表明您必须始终做一个Maven安装,我知道这是不正确的,因为有人使用Eclipse没有Maven。



Maven覆盖和Eclipse



我有也发现这让我觉得这是不可能通过香草M2E:



http://jira.codehaus.org/browse/MNGECLIPSE-599

解决方案

p>我能够完成这一切,一切都很好。以下是该做什么:



首先,您需要使用Eclipse自动识别和更新Maven依赖关系的M2E Eclipse插件。它还提供了一个漂亮的图形化POM编辑器。截至2011年底,M2Eclipse项目由Sonatype捐赠给Eclipse基金会,现在简称 M2E 。但是,它仍然没有附带Java EE版本的Eclipse Indigo,必须通过更新站点单独安装





过去,Eclipse和Maven之间的集成一直很麻烦。然而,这个新的基于Eclipse的Maven集成现在意识到在POM文件中使用了许多Maven插件,并且某些插件的某些目标在IDE环境中是有意义的。此外,在IDE中运行时有意义的目标可能需要特殊配置。为了正确处理这个M2E,现在支持连接器的概念。



M2E有很长的专用连接器列表,允许它在调用各种功能时执行Right Thing mojos(Maven插件目标)。要查看Eclipse中可用连接器的列表,请转到首选项对话框,然后选择Maven-> Dicovery-> Open Catalog。这些连接器在项目导入期间在{{pom.xml}}文件中被检测到时被自动安装。但是,这需要M2E Maven导入向导的正确版本(Indigo直到SR2才能使用)。



此外,有时这些连接器是错误的,我们需要使用夜间或测试版更新站点来获取最新的修复。如果您有较旧的或有bug的版本,则需要在升级后删除并重新导入项目。由于这些原因,在我看来,所有M2E连接器都应该在将项目导入Eclipse之前手动安装。



M2E-WTP连接器是在Eclipse服务器的Eclipse启动器中使WAR重叠工作所需要的连接器。此连接器用于将Maven与WTP集成...,从而处理WAR覆盖,servlet容器设置,Eclipse WTP配置,根上下文设置以及其他所有功能,当Maven WAR模块进行Eclipse Web工具Just Work作为项目导入Eclipse。



m2e-wtp连接器的更新站点是: http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/



添加M2E-WTP站点并安装连接器。但是请注意,M2E和M2E-WTP连接器都不会将overlay WAR的依赖关系置于最终的WAR中。您必须通过向最终的WAR pom.xml添加必需的依赖关系来执行此操作。我不知道为什么这些工具不会这样做,但是他们没有这样做 - 所以只是解决这个问题。 ; - )



此时,我还建议您通过{{帮助 - >检查更新}}进行全面更新。一旦这样做,您应该能够简单地添加一个Eclipse服务器,点击您的项目(而不是覆盖层),然后选择在服务器上运行...。



对WAR或overlay WAR进行的更改将自动发布到您的服务器。 Javascript更改发布,而不重新启动服务器...所有您需要做的是在浏览器中点击刷新以查看新的代码运行。



第二次更新:有一个错误( https://issues.sonatype.org/browse/MECLIPSEWTP- 174 ),可能导致WEB-INF / lib目录意外丢失其所有JAR文件。当这种情况发生时,您的servlet应用程序显然不会启动。解决方法是通过在服务器上单击并选择clean来清理服务器。请注意,单独清理工作目录将无法还原这些缺少的JAR。


I have a multi-module Maven project that makes use of WAR overlays (stack of them 3 deep). Everything works great in Maven, but I am unable to launch my WAR from within Eclipse because it complains of not finding various files.

How can I configure Eclipse (and a launcher) so that I can run my WAR from Eclipse without having to do a Maven Install first? I should add that my Eclipse WAR projects are not dynamic web projects...is that a part of what I need to do?

NOTE: The following question touches on the subject, but the answer indicates you must always do a Maven install first and I know that can't be right because there are folks that use Eclipse without Maven.

Maven overlays and Eclipse

I've also found this which makes me think it is not possible via vanilla M2E:

http://jira.codehaus.org/browse/MNGECLIPSE-599

解决方案

I was able to accomplish this and everything works great. Here's what to do:

First of all you need the M2E Eclipse plugin which is needed to have Eclipse automatically recognize and update Maven dependencies. It also provides a nice graphical POM editor. As of late 2011, the M2Eclipse project was donated to the Eclipse foundation by Sonatype and is now called simply M2E. However, it is still not shipped with the Java EE edition of Eclipse Indigo and must be installed separately via their update site

In the past, the integration between Eclipse and Maven has been somewhat troublesome. However, this new Eclipse based Maven integration is now aware of the fact that there are many Maven plugins used within POM files and that only certain goals of certain plug-ins make sense within an IDE environment. Furthermore, those goals that do make sense when running inside an IDE may need special configuration. To properly handle this M2E now supports the notion of a "connector"

M2E has a long list of special connectors that allow it to do the "Right Thing" when invoking various mojos (Maven plugin goals). To see the list of available connectors within Eclipse go to the Preferences dialog and select Maven->Dicovery->Open Catalog. These connectors are supposed to be installed automatically when detected within a {{pom.xml}} file during project import. However, this requires the correct version of the M2E Maven import wizard (which Indigo does not have until SR2).

In addition, sometimes these connectors are buggy and we need to use the nightly or beta updates sites to get the latest fixes. If you have an older or buggy version, then you need to delete and re-import the projects after upgrading. For these reasons, in my opinion, all M2E connectors should be installed by hand prior to importing the your project into Eclipse.

The M2E-WTP connector is the one you need to make WAR overlays work in Eclipse launchers for Eclipse "Servers". This connector is used to integrate Maven with WTP...and thus handles WAR overlays, servlet container setup, Eclipse WTP configuration, root context setting, and other things that all go towards making Eclipse web tooling "Just Work" when a Maven WAR module is imported into Eclipse as a project.

The update site for the m2e-wtp connector is: http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/

Add this M2E-WTP site and install the connector. Note however, that neither M2E nor the M2E-WTP connector are going to put dependencies of the overlay WAR into the final WAR. You must do this by adding required dependencies to the final WAR pom.xml. I don't know why the tools don't do this, but they don't -- so just get over it. ;-)

At this point, I would also recommend doing a full update via {{Help->Check for Updates}}. Once this is done, you should be able to simply add an Eclipse server, click on your project (not the overlay one, but they regular one) and choose "Run on server...".

Changes made to either the WAR or the overlay WAR will be automatically published to your server. Javascript changes are published without restarting the server...all you have to do is hit refresh in the browser to see the new code running.

Second Update: There is a bug (https://issues.sonatype.org/browse/MECLIPSEWTP-174) in M2E which can result in the WEB-INF/lib directory accidently losing all its JAR files. When this happens, your servlet application will obviously not start. The workaround is to clean the server by clicking right on the server and selecting "clean". Note that cleaning the work directory alone will not restore these missing JARs.

这篇关于如何在Eclipse中处理Maven WAR重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆