Eclipse and Maven Integration (without m2e)
This page describes how to integrate an EAR project in Eclipse or Eclipse-based IDE without m2e support. Normally however, using m2e (and m2e-wtp) should be the preferred way to integrate Maven and Eclipse. But in some rare cases that might not be possible.
If you have used mvn eclipse:eclipse
to generate the metadata for an EAR project, it will want the application.xml
file in the src/main/application/META-INF
directory.
If you edit application.xml
using the WTP based Application Deployment Descriptor editor, it will use the name of the projects (Web, EJB etc) as the name of the modules. Here is an example:
<?xml version="1.0" encoding="UTF-8"?> <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4"> <display-name>FireDragon</display-name> <module> <web> <web-uri>FireDragonWeb.war</web-uri> <context-root>firedragon</context-root> </web> </module> </application>
Obviously this does not have the typical Maven based version naming convention applied to it. This allows us to run the application internally within Eclipse using the test environments. When Maven is used to create the ear using mvn package
, it will create the versionized application.xml
file, if told to. However, by default it will not pick up the generated (versionized) one, it will use the existing one in the src/main/application/META-INF
directory.
The solution to resolve this conflict is to have Maven generate the application.xml
and use the generated one as opposed to the existing one.
This can be achieved via these two directives:
<generateApplicationXml>true</generateApplicationXml> <applicationXml>${project.build.directory}/application.xml</applicationXml>
The first line tells Maven to generate a new application.xml
file, by default in the target directory. The second line tells Maven to use it.