[英]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.在我的项目中,我同时拥有与 Web 相关的东西(jsps、控制器、..)和 EJB bean。
Now i need to build war file with web related stuff and deploy that into tomcat and现在我需要用 web 相关的东西构建 war 文件并将它部署到 tomcat 和
need to build ear file for EJB's and deploy that into jboss using maven.需要为EJB 构建ear 文件并使用maven 将其部署到jboss 中。
Can anyone suggest me a solution to modify the pom.xml accordingly.任何人都可以建议我相应地修改 pom.xml 的解决方案。
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.最好的方法是将您的项目拆分为多个子项目:一个构建 EJB,一个构建 WAR,第三个将它们打包在一起。 This is described in Maven: The Complete Reference , and with an example in Better Builds with Maven .
这在Maven: The Complete Reference 中进行了描述,并在Better Builds with Maven 中提供了一个示例。
You need to use profiles.您需要使用配置文件。 In each profile in your pom.xml you may specify any configuration you like.
在 pom.xml 中的每个配置文件中,您可以指定您喜欢的任何配置。 That configuration will be applied when you run mvn -PyourProfileName.
当您运行 mvn -PyourProfileName 时,将应用该配置。
You can fit it all in one pom.xml:你可以把它全部放在一个 pom.xml 中:
As a start, make/use your stadard "war" pom.xml.首先,制作/使用您的标准“战争” pom.xml。
Create the folder "src/main/application/META-INF".创建文件夹“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.将耳朵相关文件,如“application.xml”(强制)、“jboss-app.xml”和/或“jboss-deployment-structure.xml”放在那里。
Expand your pom.xml:展开你的 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:提示:application.xml 应如下所示:
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.