我一直关注maven-ear-plugin网站shows how to add third-party libraries to the generated application.xml上的示例。但是,它似乎没有像我预期的那样工作。同样,Web模块contextRoot也被忽略了。
根据documentation我想要做的事情应该是完全可能的。
可以使用以下方式自定义Web模块的上下文根 contextRoot参数。
请注意,第三方库(即JarModule)不是 包含在生成的application.xml中(只有ejb-client应该是 包含在java条目中)。但是,可以包含jar依赖项 在生成的application.xml中通过指定 includeInApplicationXml标志。
在我的application.xml中执行构建时,我有以下输出。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
"http://java.sun.com/dtd/application_1_3.dtd">
<application>
<display-name>MyApp.EAR</display-name>
<module>
<ejb>MyApp.jar</ejb>
</module>
<module>
<web>
<web-uri>MyApp.war</web-uri>
<context-root>/MyApp.Web</context-root>
</web>
</module>
</application>
从以下maven configuraton(pom.xml)。
...
<modelVersion>4.0.0</modelVersion>
<groupId>com.blah</groupId>
<artifactId>MyApp.EAR</artifactId>
<version>1.0</version>
<packaging>ear</packaging>
<build>
<plugins>
<plugin>
<groupId>maven-ear-plugin</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.7</version>
<configuration>
<applicationName>MyApp</applicationName>
<modules>
<ejbModule>
<groupId>com.blah</groupId>
<artifactId>MyApp.EJB</artifactId>
</ejbModule>
<webModule>
<groupId>com.blah</groupId>
<artifactId>MyApp.Web</artifactId>
<contextRoot>MyApp</contextRoot>
</webModule>
<jarModule>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<includeLibInApplicationXml>true</includeLibInApplicationXml>
</jarModule>
</modules>
<archive>
<manifestEntries>
<WebLogic-Application-Version>${weblogic.version}</WebLogic-Application-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- web and ejb modules -->
<dependency>
<groupId>com.blah</groupId>
<artifactId>MyApp.EJB</artifactId>
<version>1.0</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.blah</groupId>
<artifactId>MyApp.Web</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
</dependencies>
...
很明显,application.xml并没有按照我的意图生成。
我做错了什么?
Maven的调试如下所示。
[DEBUG] -----------------------------------------------------------------------
[DEBUG] Goal: org.apache.maven.plugins:maven-ear-plugin:2.4.2:generate-application-xml (default-generate-application-xml)
[DEBUG] Style: Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<description>${project.description}</description>
<displayName>${project.artifactId}</displayName>
<encoding default-value="UTF-8"/>
<generatedDescriptorLocation>${project.build.directory}</generatedDescriptorLocation>
<includeLibInApplicationXml default-value="false"/>
<project>${project}</project>
<version default-value="1.3"/>
<workDirectory>${project.build.directory}/${project.build.finalName}</workDirectory>
</configuration>
P.S。我尝试创建maven-ear-plugin标签,但它不会让我,因为我没有足够的信誉!如果有人可以创造我会感激。
答案 0 :(得分:9)
我按照惯例计算出来,这是用户错误。
奇怪的是,即使我的插件配置不正确,它也能正确生成EAR文件。
我替换了......
<groupId>maven-ear-plugin</groupId>
<artifactId>maven-ear-plugin</artifactId>
...与
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
然后改变了......
<includeLibInApplicationXml>true</includeLibInApplicationXml>
为...
<includeInApplicationXml>true</includeInApplicationXml>
然后它突然完成了我打算做的事情。
我的最终pom.xml看起来像这样,因为我决定自动包含所有jar。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blah</groupId>
<artifactId>MyApp.EAR</artifactId>
<version>1.0</version>
<packaging>ear</packaging>
<properties>
<weblogic.version>10.3</weblogic.version>
<weblogic.version.minor>${weblogic.version}.4</weblogic.version.minor>
<weblogic.host>***</weblogic.host>
<weblogic.port>***</weblogic.port>
<weblogic.username>***</weblogic.username>
<weblogic.password>***</weblogic.password>
</properties>
<build>
<finalName>MyApp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.7</version>
<configuration>
<applicationName>MyApp</applicationName>
<includeLibInApplicationXml>true</includeLibInApplicationXml>
<modules>
<ejbModule>
<groupId>com.blah</groupId>
<artifactId>MyApp.EJB</artifactId>
</ejbModule>
<webModule>
<groupId>com.blah</groupId>
<artifactId>MyApp.Web</artifactId>
<contextRoot>MyApp</contextRoot>
</webModule>
</modules>
<archive>
<manifestEntries>
<WebLogic-Application-Version>${weblogic.version}</WebLogic-Application-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>10.3.4</version>
<configuration>
<adminurl>t3://${weblogic.host}:${weblogic.port}</adminurl>
<user>${weblogic.username}</user>
<password>${weblogic.password}</password>
<upload>true</upload>
<action>deploy</action>
<remote>false</remote>
<verbose>true</verbose>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<name>${project.build.finalName}</name>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<versionRange>[2.7,)</versionRange>
<goals>
<goal>generate-application-xml</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>com.blah</groupId>
<artifactId>MyApp.EJB</artifactId>
<version>1.0</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>com.blah</groupId>
<artifactId>MyApp.Web</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
</dependencies>
</project>
答案 1 :(得分:1)
非常感谢,一直在寻找解决这个问题的方法几个小时了。 :) 如果这也可以帮助其他人,那么请广告我的pom。
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>appletree.be-multi</artifactId>
<groupId>be.appletree</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>appletree.be-ear</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>be.appletree</groupId>
<artifactId>appletree.be-domain</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>be.appletree</groupId>
<artifactId>appletree.be-ejb</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>be.appletree</groupId>
<artifactId>appletree.be-web</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<modules>
<jarModule>
<groupId>be.appletree</groupId>
<artifactId>appletree.be-domain</artifactId>
<includeInApplicationXml>true</includeInApplicationXml>
</jarModule>
<webModule>
<groupId>be.appletree</groupId>
<artifactId>appletree.be-web</artifactId>
</webModule>
<ejbModule>
<groupId>be.appletree</groupId>
<artifactId>appletree.be-ejb</artifactId>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>