【问题标题】:maven uber war (cargo-maven2-plugin) merging only the first <context-param> elementmaven uber war (cargo-maven2-plugin) 只合并第一个 <context-param> 元素
【发布时间】:2016-03-15 16:40:31
【问题描述】:

我正在尝试合并两个战争,从而使用 maven uber war cargo-maven2-plugin 合并 web.xml 文件。所有标签(过滤器、servlet)的合并按需要进行,但对于&lt;context-param&gt;,它仅合并 R.H.S 上 web.xml 中定义的第一个元素。我想将所有上下文参数保留在 L.H.S 上的 web.xml 上,合并我在 R.H.S 上的 web.xml 中定义的所有 &lt;context.param&gt; 元素。任何帮助,将不胜感激。这是我的代码

R.H.S 上的 web.xml

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- ** SPRING ** -->
    <context-param>
        <param-name>contextInitializerClasses</param-name>
        <param-value>com.myorg.context.MyApplicationContextInitializer</param-value>
    </context-param>

   <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:conf/spring/*.xml</param-value>
    </context-param>

   <context-param>
        <description>Location(s) to search for the Log4J config file</description>
        <param-name>log4jConfigLocation</param-name>
        <param-value>file:/dir/path/log4j.xml /WEB-INF/log4j.xml</param-value>
    </context-param>

    <context-param>
        <description>
            Boolean flag indicating whether internal Log4J debugging statements should be written. Log4J
            will write debugging messages to System.out and error messages to System.err.
        </description>
        <param-name>log4jConfigDebug</param-name>
        <param-value>false</param-value>
    </context-param>

**

  • merge.xml

**

    <?xml version="1.0"?>
<uberwar>
    <wars>
        <war>org.forgerock.openam:openam-server</war>
        <war>com.myorg.xyz.addons:my-sso-addons-web</war>
    </wars>

     <merges>
        <merge>
            <type>web.xml</type>
            <parameters>
                <default>

                    <!-- Preserve execution order of filter-mappings -->
                    <tag name="context-param">
                        <strategy name="ChooseByName">
                            <default>
                                <strategy name="Preserve" />
                            </default>
                            <choice name="contextInitializerClasses">
                                <strategy name="Overwrite" />
                            </choice>
                            <choice name="contextConfigLocation">
                                 <strategy name="Overwrite" />
                            </choice>
                            <choice name="log4jConfigLocation">
                                <strategy name="Overwrite" />
                            </choice>
                        </strategy>
                    </tag>

                    <tag name="filter-mapping">
                        <strategy name="Preserve"/>
                    </tag>

                </default>
            </parameters>
        </merge>
    </merges>
</uberwar>

pom.xml

  <!-- other entries are here -->
<packaging>uberwar</packaging>

    <build>
        <plugins>
            <!-- merges openam-server with openam-addons-web-common -->
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <!-- merges the wars -->
                    <descriptor>src/assembly/merge.xml</descriptor>
                    <configuration>
                        <type>existing</type>
                        <home>${jboss.home}/aclsso</home>
                    </configuration>
                    <deployer>
                        <type>installed</type>
                    </deployer>
                    <deployables>
                        <deployable>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <type>war</type>
                            <properties>
                                <context>openam</context>
                            </properties>
                        </deployable>
                    </deployables>
                </configuration>
            </plugin>

        </plugins>
    </build>

【问题讨论】:

    标签: maven uberjar cargo-maven2-plugin


    【解决方案1】:

    嗯,这个特殊情况下的问题是 xmlns 版本的不同,以及 web.xml 顶部的架构位置。第一场战争的版本=2.4,而第二场战争的版本=3.0。通过使用以下方法使两个 web.xml 模式保持同步解决了这个问题(我不知道为什么它合并了过滤器、servlet 标记,但合并所有 context-param 标记失败)。

    <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    

    【讨论】:

      猜你喜欢
      • 2011-08-02
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      • 2011-08-05
      • 2011-03-15
      • 2011-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多