簡體   English   中英

如何為Jetty的Maven Cargo插件指定jetty-env.xml文件?

[英]How to specify jetty-env.xml file for Maven Cargo plugin for Jetty?

我正在從Maven的jetty插件遷移到Cargo插件(cargo-maven2-plugin),因為Cargo將很樂意從依賴的Maven模塊運行WAR。 在網絡應用程序中,我們花了很大力氣通過JNDI外部化所有配置。 這些JNDI定義是特定於Web應用程序的,因此放在WAR外部的jetty-env.xml文件中。 使用Jetty插件,我們將此文件指定如下:

        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <configuration>
                <jettyEnvXml>${basedir}/target/config/jetty-env.xml</jettyEnvXml>
            </configuration>
        </plugin>

如何在Cargo Plugin中指定它? 這是我到目前為止的配置。 當然,由於缺少JNDI配置,它失敗了:

        <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>jetty6x</containerId>
                        <type>embedded</type>
                    </container>
                    <configuration>
                        <deployables>
                            <deployable>
                                <groupId>com.mycompany</groupId>
                                <artifactId>my-war-module</artifactId>
                                <type>war</type>
                                <properties>
                                   <context>/</context>
                                </properties>
                            </deployable>
                        </deployables>
                    </configuration>
                    <wait>false</wait>
                </configuration>
                <executions>
                           ......
                </executions>
        </plugin>

根據CARGO-804 ,Cargo的Jetty部署者現在支持在你的戰爭中嵌入jetty-env.xml (從版本1.0.3開始)。

為了使jetty-env.xml保持在“真正的”戰爭之外,我的建議是創建一個額外的war模塊來托管jetty-env.xml文件並配置Cargo來合並WAR文件 (特別注意<extensions>true</extensions>元素很重要,如CARGO-524中所述

我有同樣的問題,希望有一個干凈的安裝。 我沒有被WAR文件的合並所吸引。 相反,我使用程序集來維護所有外部屬性的ZIP文件。 作為一個單獨的模塊,我可以將ZIP文件的內容部署到JETTY環境。 反過來,我利用Jetty如何使用Web應用程序的名稱來加載一個免費的環境文件(對於webapps / foo.war,Jetty使用contexts / foo.xml進行配置)。 因此,雖然它不像純貨物解決方案那樣緊湊,但我更喜歡它,因為WAR文件在整個推廣過程中都沒有摻雜。 該解決方案也是管理所有配置活動的一般機制。 如果有人有興趣,我可以指出更多細節。

Mond的回答引發了一個想法,也許我可以使用Cargo的配置將我的(重命名的和略微修改的)jetty-env.xml存入“contexts”目錄。 讓我感到驚訝的是Just Worked。 我在這做了什么:

我的貨物配置中添加了以下內容:

<configfiles>  
  <configfile>  
      <file>${basedir}/../config/jetty-env.xml</file>
    <todir>contexts</todir>
     <tofile>${jetty6.context}.xml</tofile>
   </configfile>
</configfiles>

但是為了將我的jetty-env.xml轉換為真正的context.xml,我添加了以下內容:

<!-- Activates the Jetty-Plus feature so we can create/share JNDI resources -->
<Array id="plusConfig" type="java.lang.String">
    <Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
    <Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
    <Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
    <Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
    <Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
</Array>

<!-- Miscellaneous properties that were take from the CARGO version of this file that is created automatically
    (and then replaced by this file). If you ever upgrade Cargo you may need to change these. -->
<Set name="contextPath">/${jetty6.context}</Set>
<Set name="war">
    <SystemProperty name="config.home" default="."/>/webapps/${jetty6.context}.war</Set>
<Set name="extractWAR">true</Set>
<Set name="defaultsDescriptor">
    <SystemProperty name="config.home" default="."/>/etc/webdefault.xml</Set>
<Set name="ConfigurationClasses">
    <Ref id="plusConfig" />
</Set>

我擔心CARGO會在它復制我的文件之后轉儲它自己的上下文文件,但它很聰明,可以最后復制我的文件。

我想做的其他事情是過濾屬性。 到目前為止我有這個:

    <profile>
        <id>deploy-properties</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <properties>
            <deployable.classifier>properties</deployable.classifier>
            <deployable.type>zip</deployable.type>
            <ys.imq.user>UserFromDeploymentPom</ys.imq.user>
            <ys.imq.password>PasswordFromDeploymentPom</ys.imq.password>
        </properties>
        <dependencies>
            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>${deployable.artifactId}</artifactId>
                <classifier>${deployable.classifier}</classifier>
                <type>${deployable.type}</type>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>process-resources</phase>
                            <goals>
                                <goal>unpack</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>${deployable.artifactId}</artifactId>
                                <classifier>${deployable.classifier}</classifier>
                                <version>${project.version}</version>
                                <type>${deployable.type}</type>
                                <overWrite>true</overWrite>
                                <outputDirectory>/tmp/${deployable.artifactId}</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.4.3</version>
                    <executions>
                        <execution>
                            <id>copy-resources</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${deploy.jettyHome}</outputDirectory>
                                <overwrite>true</overwrite>
                                <resources>
                                    <resource>
                                        <directory>/tmp/${deployable.artifactId}</directory>
                                        <filtering>true</filtering>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

它比我喜歡的要復雜一些,但允許我在將它們添加到Jetty時過濾屬性。 這使得可以使用系統屬性覆蓋密碼和其他機密數據。 我們正在使用Bamboo(我猜Hudson類似),可以調整每個環境的計划。 計划可能受訪問控制。 這使我們可以在一個地方設置所有部署屬性,因此不再有管理員在Unix機器上進行攻擊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM