简体   繁体   中英

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

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.

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?

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)

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. Just use this, in your web-app's 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

 mvn clean install jetty:run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM