[英]Maven and Cargo: start Jetty-Container with war-File
I just started a new Maven project that is intended to start a Jetty containing a war-File from a depended project. 我刚刚开始了一个新的Maven项目,该项目旨在启动包含来自依赖项目的war-File的Jetty。 The cargo-plugin should be the right tool for this.
货物插件应该是正确的工具。
Unfortunately it doesn't work for me. 不幸的是,它对我不起作用。 It starts Jetty successfully but it only contains the default-cargo-war-file, not the expected one.
它成功启动了Jetty,但它只包含default-cargo-war-file,而不是预期的文件。
This is the relevant part of my war-File: 这是我的战争文件的相关部分:
<dependencies>
<dependency>
<groupId>com.group</groupId>
<artifactId>my-webapp</artifactId>
<version>0.1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.5</version>
<configuration>
<container>
<containerId>jetty7x</containerId>
<type>embedded</type>
</container>
<configuration>
<properties>
<cargo.servlet.port>7070</cargo.servlet.port>
<cargo.logging>high</cargo.logging>
</properties>
</configuration>
<deployer>
<type>embedded</type>
<deployables>
<deployable>
<groupId>com.group</groupId>
<type>war</type>
<artifactId>my-webapp</artifactId>
<properties>
<context>/path</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</plugin>
</plugins>
</build>
I use the plugin by starting mvn cargo:start. 我通过启动mvn cargo:start来使用插件。
There is no error log output. 没有错误日志输出。
[INFO] [cargo:start]
[INFO] [beddedLocalContainer] Jetty 7.x Embedded starting...
2011-01-17 18:57:44.586:INFO::jetty-7.2.0.v20101020
2011-01-17 18:57:44.663:INFO::Extract jar:file:/tmp/cargo/conf/cargocpc.war!/ to /tmp/jetty-0.0.0.0-7070-cargocpc.war-_cargocpc-any-/webapp
2011-01-17 18:57:45.082:INFO::Started SelectChannelConnector@0.0.0.0:7070
[INFO] [beddedLocalContainer] Jetty 7.x Embedded started on port [7070]
How can I tell Cargo to load the specified war-File? 如何告诉Cargo加载指定的war-File?
Ok, I got it to work now. 好的,我现在就开始工作了。
As it seems, cargo silently ignores any snapshot dependencies. 看起来,货物默默地忽略任何快照依赖。 So you have to release a project before using it in a cargo-project.
因此,您必须在货物项目中使用之前发布项目。
Probably this is a bug. 可能这是一个错误。 I can't imagine any sensible reason for this behaviour.
我无法想象这种行为有任何明智的原因。
(also the pom-File I posted above was not correct, you have to adapt the changes that Robin suggests in his answer) (也是我上面发布的pom-File不正确,你必须调整Robin在他的答案中建议的变化)
Try this. 试试这个。 Set your configuration type to standalone and put the deployables in the configuration.
将配置类型设置为独立 ,并将可部署的内容放入配置中。 Make sure the correct project dependency exists to resolve the war.
确保存在正确的项目依赖关系来解决战争。
<configuration>
<type>standalone</type>
<properties>
<cargo.servlet.port>7070</cargo.servlet.port>
<cargo.logging>high</cargo.logging>
</properties>
<deployables>
<deployable>
<groupId>com.group</groupId>
<type>war</type>
<artifactId>my-webapp</artifactId>
<properties>
<context>/path</context>
</properties>
</deployable>
</deployables>
</configuration>
它似乎可以更好地工作如果你第一次部署说运行命令“mvn cargo:deploy”然后运行“mvn cargo:start”
If you just want to deploy on embedded Jetty, you may not need Cargo. 如果您只想在嵌入式Jetty上部署,则可能不需要Cargo。 Just use this, in your web-app's pom.xml:
只需在您的web-app的pom.xml中使用它:
<build>
...
...
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.2.2.v20101205</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppConfig>
<contextPath>/path</contextPath>
</webAppConfig>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>7070</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
...
...
</plugins>
...
...
</build>
to build and start Jetty user 构建并启动Jetty用户
mvn clean install jetty:run
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.