如何为 Jetty 的 Maven Cargo 插件指定 jetty-env.xml 文件?
我正在从 Maven 的 jetty 插件迁移到 Cargo 插件 (cargo-maven2-plugin),因为 Cargo 会很乐意从依赖的 Maven 模块运行 WAR。在我们的 Web 应用程序中,我们煞费苦心地通过 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 插件中指定此文件?这是我到目前为止的配置。当然,由于缺少 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>
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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 CARGO-804,Cargo 的 Jetty 部署程序现在支持嵌入 jetty-env .xml 在你的 war 中(从版本 1.0.3 开始)。
为了将jetty-env.xml保持在“真正的”战争之外,我的建议是创建一个额外的war模块来托管jetty-env.xml文件并配置 Cargo 来合并 WAR 文件(特别注意
< ;extensions>true
元素很重要,如 CARGO-524 中所述)。According to CARGO-804, Cargo's Jetty deployer now supports embedding a jetty-env.xml inside your war (as of version 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 thejetty-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).我有同样的问题并希望进行全新安装。我对 WAR 文件的合并不感兴趣。相反,我使用程序集来维护所有外部属性的 ZIP 文件。作为一个单独的模块,我可以将 ZIP 文件的内容部署到 JETTY 环境。反过来,我利用 Jetty 如何使用 Web 应用程序的名称来加载免费环境文件(对于 webapps/foo.war,Jetty 使用 contexts/foo.xml 进行配置)。因此,虽然它不像纯粹的 Cargo 解决方案那么紧凑,但我更喜欢它,因为 WAR 文件在整个升级过程中的进展是纯粹的。该解决方案也是管理所有配置活动的通用机制。如果有人感兴趣,我可以指出更多细节。
I share the same problem and desire to have a clean install. I was not attracted by the merging of WAR files. Instead I use an assembly to maintain a ZIP file of all external properties. As a separate module I can then deploy the contents of the ZIP file to the JETTY environment. 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). 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. The solution is also a general mechanism to manage all configuration activities. I can point to more details if anyone is interested.
Mond 的回答引发了一个想法,也许我可以使用 Cargo 的配置将我的(重命名并稍作修改的)jetty-env.xml 存入“contexts”目录中。令我惊讶的是,它竟然奏效了。我做了什么:
在我的货物配置中添加了以下内容:
但是为了将 jetty-env.xml 变成真正的 context.xml,我添加了以下内容:
我担心 CARGO 会在复制后转储自己的上下文文件我的在那里,但它很聪明,最后复制了我的。
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:
But in order to turn my jetty-env.xml into a real context.xml I added the following:
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 的同时过滤属性。这使得可以使用系统属性覆盖密码和其他机密数据。我们正在使用 Bamboo(我猜 Hudson 是类似的),并且可以根据环境调整计划。计划可能受到访问控制。这使我们能够在一个地方设置所有部署属性,这样管理员就不会再对 Unix 机器进行黑客攻击了。
Something else I want to do is to filter properties. So far I have this:
Its a bit more complicated than I like but allows me to filter properties whilst adding them to 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. 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.