开发者

Building both war and ear files for same project using maven

In my project i have both web开发者_如何学JAVA 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


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.


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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜