maven-ear-plugin contextRoot 被忽略
maven-ear-plugin contextRoot ignored
我一直在使用 maven-ear-plugin 创建耳包并使用自定义 contextRoot 生成 application.xml(一切正常)。现在我想创建 2 个耳包并将它们部署在不同的上下文路径下,所以我定义了具有 2 个执行的插件。但出于某种原因,maven-ear-plugin 忽略了 contextRoot 属性 并且在生成的 application.xml 中它在双耳中使用 artifactId 而不是 contextRoot(因此它们具有相同的上下文根 "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>
有什么建议吗?
问题是您只生成一次 application.xml
而您需要两个 application.xml
。为此,您还需要将 generate-application-xml
目标的两次执行绑定到 Maven 生命周期的 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 等相关的两次执行的文件夹相同,这只是一个草稿 ;)
我一直在使用 maven-ear-plugin 创建耳包并使用自定义 contextRoot 生成 application.xml(一切正常)。现在我想创建 2 个耳包并将它们部署在不同的上下文路径下,所以我定义了具有 2 个执行的插件。但出于某种原因,maven-ear-plugin 忽略了 contextRoot 属性 并且在生成的 application.xml 中它在双耳中使用 artifactId 而不是 contextRoot(因此它们具有相同的上下文根 "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>
有什么建议吗?
问题是您只生成一次 application.xml
而您需要两个 application.xml
。为此,您还需要将 generate-application-xml
目标的两次执行绑定到 Maven 生命周期的 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 等相关的两次执行的文件夹相同,这只是一个草稿 ;)