![](/img/trans.png)
[英]Platform dependent .war-file produced with maven and Jersey/Jackson setting?
[英]Maven and Cargo: start Jetty-Container with war-File
我刚刚开始了一个新的Maven项目,该项目旨在启动包含来自依赖项目的war-File的Jetty。 货物插件应该是正确的工具。
不幸的是,它对我不起作用。 它成功启动了Jetty,但它只包含default-cargo-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>
我通过启动mvn cargo:start来使用插件。
没有错误日志输出。
[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]
如何告诉Cargo加载指定的war-File?
好的,我现在就开始工作了。
看起来,货物默默地忽略任何快照依赖。 因此,您必须在货物项目中使用之前发布项目。
可能这是一个错误。 我无法想象这种行为有任何明智的原因。
(也是我上面发布的pom-File不正确,你必须调整Robin在他的答案中建议的变化)
试试这个。 将配置类型设置为独立 ,并将可部署的内容放入配置中。 确保存在正确的项目依赖关系来解决战争。
<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”
如果您只想在嵌入式Jetty上部署,则可能不需要Cargo。 只需在您的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>
构建并启动Jetty用户
mvn clean install jetty:run
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.