首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >忽略maven-ear-plugin contextRoot

忽略maven-ear-plugin contextRoot
EN

Stack Overflow用户
提问于 2015-05-22 08:18:39
回答 1查看 2.7K关注 0票数 1

我一直在使用maven- ear插件来创建ear包,并使用自定义的application.xml生成contextRoot (一切都很好)。现在我想要创建两个ear包,并在不同的上下文路径下部署它们,所以我用2次执行定义了插件。但出于某种原因,maven-ear插件忽略了contextRoot属性,而在生成的application.xml中,它在两耳中使用artifactId而不是contextRoot (因此它们具有相同的上下文根"app-ui")。这是我的maven-ear-plugin定义:

代码语言:javascript
复制
<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>

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-22 15:48:58

问题是,您只生成一次application.xml,而需要两个application.xml。为此,还需要在maven生命周期的generate-application-xml阶段上执行两次绑定的generate-resources目标,以便用以下两种不同的配置生成application.xml文件两次(最好是在两个不同的文件夹中^):

代码语言:javascript
复制
<!-- 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有关的两次执行的文件夹是相同的,这只是一个草案;)

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30391681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档