本文介绍了如何为Jetty的Maven Cargo插件指定jetty-env.xml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

如何在货物插件中指定这个?这是我到目前为止的配置。当然,由于缺少JNDI配置,它失败了:

How does one go about specifying this within the Cargo Plugin? Here's the configuration I have so far. It is, of course, failing because of the absent JNDI configuration:

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


推荐答案

Mond的回答引发了一个想法,也许我可以使用配置Cargo将我的(重命名的和略微修改的)jetty-env.xml存入contexts目录。令我惊讶的是Just Worked。我在这里做了什么:

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. To my amazement it 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>

但为了将我的jetty-env.xml转换为真正的context.xml,我添加了以下内容:

But in order to turn my jetty-env.xml into a real context.xml I added the following:

<!-- 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会在我复制我的文件后转储它自己的上下文文件,但它很聪明足以复制我的最后一次。

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.

这篇关于如何为Jetty的Maven Cargo插件指定jetty-env.xml文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 11:45