Pawan
Pawan

Reputation: 273

Building both war and ear files for same project using maven


In my project i have both web related stuff(jsps, controllers, ..) and EJB beans.
Now i need to build war file with web related stuff and deploy that into tomcat and
need to build ear file for EJB's and deploy that into jboss using maven.

Can anyone suggest me a solution to modify the pom.xml accordingly.

Thank you,
Pavan

Upvotes: 2

Views: 4135

Answers (3)

YumikoTanaka
YumikoTanaka

Reputation: 11

You can fit it all in one pom.xml:

As a start, make/use your stadard "war" pom.xml.

Create the folder "src/main/application/META-INF".

Put the ear relevant files like "application.xml" (mandatory), "jboss-app.xml" and/or "jboss-deployment-structure.xml" in there.

Expand your pom.xml:

<resources>
    <resource>
        <directory>src/main/application</directory>
        <filtering>true</filtering>
        <includes>
            <include>META-INF/*.xml</include>
        </includes>
    </resource>
</resources>

and further:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <tasks>
                        <ear
                            destfile="${project.build.directory}/${project.build.finalName}.ear"
                            appxml="${project.build.outputDirectory}/META-INF/application.xml">
                            <fileset dir="${project.build.outputDirectory}"
                                includes="META-INF/*.xml" excludes="META-INF/application.xml" />
                            <fileset dir="${project.build.directory}"
                                includes="${project.build.finalName}.war" />
                        </ear>
                    </tasks>
                </configuration>
            </execution>
        </executions>
    </plugin>

hint: application.xml should look like:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6">
  <display-name>XXX.ear</display-name>
  <module>
    <web>
      <web-uri>XXX.war</web-uri>
      <context-root>XXX</context-root>
    </web>
  </module>
</application>

Upvotes: 0

Anon
Anon

Reputation: 2348

The best way is to split your project into multiple sub-projects: one builds the EJBs, one builds the WAR, and a third packages them together. This is described in Maven: The Complete Reference, and with an example in Better Builds with Maven.

Upvotes: 3

weekens
weekens

Reputation: 8292

You need to use profiles. In each profile in your pom.xml you may specify any configuration you like. That configuration will be applied when you run mvn -PyourProfileName.

Upvotes: 1

Related Questions