4

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?

tautologe
  • 1,781
  • 2
  • 15
  • 14

4 Answers4

3

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)

tautologe
  • 1,781
  • 2
  • 15
  • 14
1

Its seems it could work better if you first do the deployment say run a command "mvn cargo:deploy" then run a "mvn cargo:start"

1

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>           
saurshaz
  • 489
  • 5
  • 17
Robin
  • 24,062
  • 5
  • 49
  • 58
  • Thanks, you are right. I had tried this before and it didn't work, so I tried to use the deployer-Element. The real problem was that cargo seems to ignore snapshot dependencies. – tautologe Jan 18 '11 at 10:49
0

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
Nishant
  • 54,584
  • 13
  • 112
  • 127
  • 1
    This would require him to run mvn against a different pom in a different project first. He wants to deploy a dependent war from a project, and jetty doesn't do this very well. I would assume for some type of integration testing. – Robin Jan 17 '11 at 20:32
  • 1
    It is best suited for dev environment where you code, and immediately deploy. You just put this piece of XML in you web-app's pom.xml and add `mvn clean install jetty:run` to `run > run configuration` menu. Now, whenever you need to test, you will just click this menu item, the build is done and app is deplyed and server is up and running. clean. – Nishant Jan 17 '11 at 20:58
  • Nishant, that's not what he wants to do. He wants to do java -jar myproject.war – Rafael Sanches Mar 21 '12 at 05:34
  • @RafaelSanches Looks like OP has answered himself. So, see what he wanted. – Nishant Mar 21 '12 at 05:41