Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
260 views
in Technique[技术] by (71.8m points)

java - How to handle Maven WAR overlays in Eclipse?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...