简体   繁体   English

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

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

I am migrating from Maven's jetty plugin to the Cargo plugin (cargo-maven2-plugin) because Cargo will happily run WARs from dependent Maven modules. 我正在从Maven的jetty插件迁移到Cargo插件(cargo-maven2-plugin),因为Cargo将很乐意从依赖的Maven模块运行WAR。 Within out web-app we have taken great pains to externalize all configuration through JNDI. 在网络应用程序中,我们花了很大力气通过JNDI外部化所有配置。 These JNDI definitions are web-app specific and therefore are placed in a jetty-env.xml file that is outside the WAR. 这些JNDI定义是特定于Web应用程序的,因此放在WAR外部的jetty-env.xml文件中。 Using the Jetty plugin, we specified this file as follows: 使用Jetty插件,我们将此文件指定如下:

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

How does one go about specifying this within the Cargo Plugin? 如何在Cargo Plugin中指定它? Here's the configuration I have so far. 这是我到目前为止的配置。 It is, of course, failing because of the absent JNDI configuration: 当然,由于缺少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>

According to CARGO-804 , Cargo's Jetty deployer now supports embedding a jetty-env.xml inside your war (as of version 1.0.3). 根据CARGO-804 ,Cargo的Jetty部署者现在支持在你的战争中嵌入jetty-env.xml (从版本1.0.3开始)。

And in order to keep the jetty-env.xml outside your "real" war, my suggestion would be to create an additional war module to host the jetty-env.xml file and configure Cargo to merge WAR files (pay a special attention to the <extensions>true</extensions> element which is important, as mentioned in CARGO-524 ). 为了使jetty-env.xml保持在“真正的”战争之外,我的建议是创建一个额外的war模块来托管jetty-env.xml文件并配置Cargo来合并WAR文件 (特别注意<extensions>true</extensions>元素很重要,如CARGO-524中所述

I share the same problem and desire to have a clean install. 我有同样的问题,希望有一个干净的安装。 I was not attracted by the merging of WAR files. 我没有被WAR文件的合并所吸引。 Instead I use an assembly to maintain a ZIP file of all external properties. 相反,我使用程序集来维护所有外部属性的ZIP文件。 As a separate module I can then deploy the contents of the ZIP file to the JETTY environment. 作为一个单独的模块,我可以将ZIP文件的内容部署到JETTY环境。 In turn, I leverage how Jetty uses the name of the web app to load a complimentary environment file (for webapps/foo.war Jetty uses contexts/foo.xml for configuration). 反过来,我利用Jetty如何使用Web应用程序的名称来加载一个免费的环境文件(对于webapps / foo.war,Jetty使用contexts / foo.xml进行配置)。 So, whilst it's not as compact as a pure Cargo solution I prefer it since the WAR file is unadulterated in its progress throughout the promotion process. 因此,虽然它不像纯货物解决方案那样紧凑,但我更喜欢它,因为WAR文件在整个推广过程中都没有掺杂。 The solution is also a general mechanism to manage all configuration activities. 该解决方案也是管理所有配置活动的一般机制。 I can point to more details if anyone is interested. 如果有人有兴趣,我可以指出更多细节。

Mond's answer sparked an idea that perhaps I could use the configuration of Cargo to deposit my (renamed and slightly modified) jetty-env.xml into the "contexts" directory. Mond的回答引发了一个想法,也许我可以使用Cargo的配置将我的(重命名的和略微修改的)jetty-env.xml存入“contexts”目录。 To my amazement it Just Worked. 让我感到惊讶的是Just Worked。 Here what I did: 我在这做了什么:

To my cargo configuration I added the following: 我的货物配置中添加了以下内容:

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

But in order to turn my jetty-env.xml into a real context.xml I added the following: 但是为了将我的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>

I was worried that CARGO would dump its own context file AFTER it copied mine there, but it was smart enough to copy mine last. 我担心CARGO会在它复制我的文件之后转储它自己的上下文文件,但它很聪明,可以最后复制我的文件。

Something else I want to do is to filter properties. 我想做的其他事情是过滤属性。 So far I have this: 到目前为止我有这个:

    <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>

Its a bit more complicated than I like but allows me to filter properties whilst adding them to Jetty. 它比我喜欢的要复杂一些,但允许我在将它们添加到Jetty时过滤属性。 This enables passwords and other confidential data to be overriden using system properties. 这使得可以使用系统属性覆盖密码和其他机密数据。 We are using Bamboo (I guess Hudson is similar) and one can adjust plans per environment. 我们正在使用Bamboo(我猜Hudson类似),可以调整每个环境的计划。 Plans can be subject to access control. 计划可能受访问控制。 This allows us to have one place to set all deployment properties, so no more admins hacking on the Unix boxes. 这使我们可以在一个地方设置所有部署属性,因此不再有管理员在Unix机器上进行攻击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM