如何在 Eclipse 中处理 Maven WAR 覆盖?
我有一个多模块 Maven 项目,它使用 WAR 覆盖层(堆栈有 3 层深)。 Maven 中的一切都运行良好,但我无法从 Eclipse 中启动 WAR,因为它抱怨找不到各种文件。
如何配置 Eclipse(和启动器),以便可以从 Eclipse 运行 WAR,而无需先进行 Maven 安装?我应该补充一点,我的 Eclipse WAR 项目不是动态 Web 项目...这是我需要做的一部分吗?
注意:下面的问题涉及到这个主题,但答案表明您必须始终首先安装 Maven,我知道这是不对的,因为有些人在没有 Maven 的情况下使用 Eclipse。
我还发现了这一点,这让我认为通过 vanilla 是不可能的M2E:
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.
I've also found this which makes me think it is not possible via vanilla M2E:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够完成这个任务并且一切都很好。要做的事情如下:
首先,您需要 M2E Eclipse 插件,该插件需要 Eclipse 自动识别和更新 Maven 依赖项。它还提供了一个很好的图形 POM 编辑器。截至 2011 年底,M2Eclipse 项目由 Sonatype 捐赠给 Eclipse 基金会,现在简称为 M2E 。但是,它仍然没有随 Eclipse Indigo 的 Java EE 版本一起提供,必须通过其更新站点单独安装
过去,Eclipse 和 Maven 的集成有些麻烦。然而,这种新的基于 Eclipse 的 Maven 集成现在意识到了这样一个事实:POM 文件中使用了许多 Maven 插件,并且只有某些插件的某些目标在 IDE 环境中才有意义。此外,那些在 IDE 中运行时确实有意义的目标可能需要特殊配置。为了正确处理此问题,M2E 现在支持“连接器”的概念,
M2E 有一个很长的特殊连接器列表,允许它在调用各种 mojo(Maven 插件目标)时执行“正确的操作”。要查看 Eclipse 中可用连接器的列表,请转至“首选项”对话框并选择 Maven->Dicovery->Open Catalog。当项目导入期间在 {{pom.xml}} 文件中检测到时,这些连接器应该会自动安装。然而,这需要正确版本的 M2E Maven 导入向导(Indigo 直到 SR2 才具备)。
此外,有时这些连接器存在缺陷,我们需要使用夜间或测试版更新站点来获取最新的修复程序。如果您有旧版本或有错误的版本,则需要在升级后删除并重新导入项目。出于这些原因,我认为,在将项目导入 Eclipse 之前,应手动安装所有 M2E 连接器。
M2E-WTP 连接器是使 WAR 覆盖在 Eclipse“服务器”的 Eclipse 启动器中工作所需的连接器。该连接器用于将 Maven 与 WTP 集成...从而处理 WAR 覆盖、servlet 容器设置、Eclipse WTP 配置、根上下文设置以及其他所有事项,这些事项都有助于在 Maven WAR 模块时使 Eclipse Web 工具“正常工作”作为项目导入到 Eclipse 中。
m2e-wtp 连接器的更新站点是:
http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/
添加此 M2E-WTP 站点并安装连接器。但请注意,M2E 和 M2E-WTP 连接器都不会将覆盖 WAR 的依赖项放入最终 WAR 中。您必须通过将所需的依赖项添加到最终的 WAR pom.xml 来完成此操作。我不知道为什么这些工具不这样做,但他们不这样做——所以就克服它吧。 ;-)
此时,我还建议通过 {{Help->Check for Updates}} 进行完整更新。完成此操作后,您应该能够简单地添加一个 Eclipse 服务器,单击您的项目(不是覆盖项目,而是常规项目)并选择“在服务器上运行...”。
对 WAR 或覆盖 WAR 所做的更改将自动发布到您的服务器。 Javascript 更改无需重新启动服务器即可发布...您所要做的就是在浏览器中点击刷新即可查看新代码的运行情况。
第二次更新:存在一个错误 (https://issues.sonatype. org/browse/MECLIPSEWTP-174) 在 M2E 中,这可能会导致 WEB-INF/lib 目录意外丢失其所有 JAR 文件。当这种情况发生时,您的 servlet 应用程序显然将无法启动。解决方法是通过右键单击服务器并选择“清理”来清理服务器。请注意,仅清理工作目录并不能恢复这些丢失的 JAR。
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.