我一直在使用maven-ear-plugin来创建ear bundle并使用自定义contextRoot生成application.xml(一切正常)。现在我想创建2个ear bundle并在不同的上下文路径下部署它们,所以我定义了2个执行插件。但由于某种原因,maven-ear-plugin忽略了contextRoot属性,并且在生成的application.xml中,它在两个耳中使用artifactId而不是contextRoot(因此它们具有相同的context-root" app-ui")。 这是我的maven-ear-plugin定义:
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>app1</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<finalName>app1</finalName>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
<contextRoot>/app1-ui</contextRoot>
</webModule>
</modules>
</configuration>
</execution>
<execution>
<id>app2</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<finalName>app2</finalName>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
<contextRoot>/app2-ui</contextRoot>
</webModule>
</modules>
</configuration>
</execution>
有什么建议吗?
答案 0 :(得分:3)
问题是,只需要生成application.xml
一次,而您需要两个application.xml
。为此,您还需要在maven生命周期的generate-application-xml
阶段同时执行绑定generate-resources
目标的两次执行,以便生成application.xml
文件两次(最好在两个不同的文件夹中^ ^)有两种不同的配置,如:
<!-- first execution for the first application.xml in folder target/app1/META-INF -->
<execution>
<id>appxml-app1</id>
<phase>generate-resources</phase>
<goals>
<goal>generate-application-xml</goal>
</goals>
<configuration>
<generatedDescriptorLocation>target/app1/META-INF</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
<contextRoot>/app1-ui</contextRoot>
</webModule>
</modules>
</configuration>
</execution>
<!-- first execution for the generation of the ear with the application.xml in folder target/app1 -->
<execution>
<id>app1</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<workDirectory>target/app1</workDirectory>
<finalName>app1</finalName>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
</webModule>
</modules>
</configuration>
</execution>
<!-- second execution for the second application.xml in folder target/app2/META-INF -->
<execution>
<id>appxml-app2</id>
<phase>generate-resources</phase>
<goals>
<goal>generate-application-xml</goal>
</goals>
<configuration>
<generatedDescriptorLocation>target/app2/META-INF</generatedDescriptorLocation>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
<contextRoot>/app2-ui</contextRoot>
</webModule>
</modules>
</configuration>
</execution>
<!-- second execution for the generation of the ear with the application.xml in folder target/app2 -->
<execution>
<id>app2</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<workDirectory>target/app2</workDirectory>
<finalName>app2</finalName>
<modules>
<webModule>
<groupId>com.x.y</groupId>
<artifactId>app-ui</artifactId>
</webModule>
</modules>
</configuration>
</execution>
为了改善这一点,您可以使用变量来确保关于app1等的两个执行文件的文件夹相同,这只是一个草稿;)