Maven和Cargo:使用war文件启动Jetty容器

4
我刚开始一个新的Maven项目,旨在启动Jetty并包含来自依赖项目的war文件。 cargo-plugin 应该是正确的工具。
不幸的是,它对我不起作用。它成功地启动了Jetty,但它只包含默认的 cargo-war-file,而不是预期的文件。
这是我的 war 文件的相关部分:
<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文件?

4个回答

3

好的,我现在已经把它搞定了。

看起来,Cargo默默地忽略了任何快照依赖项。因此,在在cargo项目中使用之前,您必须发布该项目。

这可能是一个bug。我无法想象这种行为有任何合理的原因。

(另外,我上面发布的pom文件不正确,您需要根据Robin在他的回答中建议的更改进行调整)


1
"cargo默默地忽略任何快照依赖关系"??/??/??好知道。我想我刚刚被咬了... - Jonas N
极不可能。我正在使用快照运行货物,没有问题。 - Genry

1

如果您先执行部署命令"mvn cargo:deploy",然后再运行"mvn cargo:start",似乎可以使其更好地工作。


1
尝试这个。将您的配置类型设置为独立,并将可部署项放置在配置中。确保存在正确的项目依赖项以解决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>           

谢谢,你说得对。我之前尝试过这个方法,但没有成功,所以我尝试使用deployer元素。真正的问题是cargo似乎忽略了快照依赖。 - tautologe

0

如果您只想在嵌入式Jetty上部署,可能不需要使用Cargo。只需在您的Web应用程序的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

1
这将要求他首先针对不同项目中的不同pom运行mvn。他想从一个项目部署一个依赖的war包,而jetty并不是很擅长这样做。我会认为这是某种类型的集成测试。 - Robin
1
它最适合于开发环境,在这里您可以编写代码并立即部署。您只需将此XML片段放入Web应用程序的pom.xml文件中,并将mvn clean install jetty:run添加到运行>运行配置菜单中。现在,每当您需要进行测试时,只需单击此菜单项,构建完成后,应用程序将被部署并且服务器已经启动运行。完美无瑕。 - Nishant
Nishant,那不是他想要做的。他想要执行java -jar myproject.war。 - Rafael Sanches
@RafaelSanches 看起来似乎 OP 自己已经回答了。所以看看他想要什么。 - Nishant

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接