gpt4 book ai didi

java - maven-ear-plugin contextRoot 被忽略

转载 作者:行者123 更新时间:2023-11-29 03:09:09 24 4
gpt4 key购买 nike

我一直在使用 maven-ear-plugin 创建 ear bundle 并使用自定义 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 目标的两次执行绑定(bind)到 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 等相关的两次执行的文件夹相同,这只是一个草稿 ;)

关于java - maven-ear-plugin contextRoot 被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30391681/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com