【问题标题】:maven-ear-plugin contextRoot ignoredmaven-ear-plugin contextRoot 被忽略
【发布时间】:2015-05-22 08:18:39
【问题描述】:

我一直在使用 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>

有什么建议吗?

【问题讨论】:

  • classifier 添加到其中一项执行中,这意味着将`Second' 添加到其中一项执行配置中并重试。
  • 我尝试添加分类器,但结果仍然相同。它只是将分类器添加到耳朵文件名。
  • 你能把示例项目或真实项目放在某个地方,这样看起来也更简单。
  • 当然。我放在bitbucket上,可以克隆: git clone dd_repo@bitbucket.org/dd_repo/app.git 先构建app-ui,再构建app-ear。 app1.ear 和 app2.ear 都将被创建,并且两者都将在 META-INF/application.xml 中具有相同的上下文根

标签: java maven maven-ear-plugin


【解决方案1】:

问题是您只生成一次application.xml,而您需要两个application.xml。为此,您还需要在 maven 生命周期的 generate-resources 阶段绑定两个 generate-application-xml 目标的执行,以便使用两种不同的配置两次生成 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 等的两次执行的文件夹相同,这只是一个草稿;)

【讨论】:

  • 你说得对,法比恩。非常感谢!
猜你喜欢
  • 2011-07-30
  • 2020-08-30
  • 1970-01-01
  • 2014-02-23
  • 1970-01-01
  • 1970-01-01
  • 2023-03-31
  • 2020-09-30
  • 1970-01-01
相关资源
最近更新 更多