You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by richard schmidt <ha...@gmail.com> on 2008/12/11 21:47:34 UTC

Starting a jetty server for client side tests

I have a  WAR project that exposes some web services
I also have a JAR project that acts as a client application for the web
services. The client application makes http requests to the web services.

To run unit tests I need to set up a jetty server running the web services.

I have tried the following

1) use the maven-dependency-plugin to extract the correct WAR from the
repository and copy it to sub directory in target.

2) use the maven-jetty-plugin to start a server running the WAR downloaded
in the previous step.  The server can be started before running the unit
tests and stopped when the tests have finished.

The jetty plugin is as follows


<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<stopPort>9966</stopPort>
<webApp>
${basedir}/target/iceCreamWar/ICECream.war
</webApp>
<stopKey>stop</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>stop-jetty</id>
<phase>prepare-package</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>

However if I run it I get the following error message

[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] Webapp source directory
C:\Workspace_MavenBuild\ICECreamClient\src\main\webapp does not exist

which is expected as the "run"goal assumes you have a normal web project
with a context.

If I change the goal to "run-war", then the jetty server does start for the
unit test, but only afterwoods. - the jetty documentation talks about
"Invokes the execution of the lifecycle phase package prior to executing
itself." which I presume is what is happening.

Any ideas how to get around this one?

Richard

Re: Starting a jetty server for client side tests

Posted by Wayne Fay <wa...@gmail.com>.
> <plugin>
> <groupId>org.codehaus.cargo</groupId>
> <artifactId>cargo-maven2-plugin</artifactId>

No version declared for a plugin gives unpredictable results. It is
possible that the version of cargo that Maven has chosen to use for
this particular build does not support the <deployables> syntax that
you are using, or there's a bug related to it.

You really should post this on the Cargo Users list anyway...

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Starting a jetty server for client side tests

Posted by richard schmidt <ha...@gmail.com>.
Gave it a try - it almost works!
Based on the example projects, I tried the following

1) Added a normal dependency ( icecream.war.version} is defined elsewhere

               <dependency>
<groupId>com.metservice</groupId>
<artifactId>ICECream</artifactId>
<version>${icecream.war.version}</version>
<type>war</type>
</dependency>

2) Added the cargo plug

<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>true</wait>
<container>
<containerId>jetty6x</containerId>
<log>
${project.build.directory}/${containerId}/cargo.log
</log>
<type>embedded</type>
</container>

<deployables>
<deployable>
<groupId>com.metservice</groupId>
<artifactId>ICECream</artifactId>
<type>war</type>
<properties>
<context>ICECream</context>
</properties>

</deployable>
</deployables>

</configuration>
</plugin>

3) ran the cargo:start target....


Jetty started on port 8080 but did not deploy my WAR - only a thing called
cargocpc.war

I cant see anything obviously wrong????

Richard

RE: Starting a jetty server for client side tests

Posted by "Edelson, Justin" <Ju...@mtvstaff.com>.
You might want to try using cargo instead. It should allow you to deploy
the WAR project into a container and start up that container.

Something like:
<configuration>
  <wait>true</wait>
  <container>
    <containerId>jetty6x</containerId>
  </container>
  <configuration>
    <deployables>
      <deployable>
         <groupId>GROUP_ID</groupId>
         <artifactId>ARTIFACT_ID</artifactId>
         <version>VERSION</version>
         <type>war</type>
      </deployable>
    </deployables>
  </configuration>
  ...
</configuration> 

-----Original Message-----
From: richard schmidt [mailto:hangstrap@gmail.com] 
Sent: Thursday, December 11, 2008 3:48 PM
To: users@maven.apache.org
Subject: Starting a jetty server for client side tests

I have a  WAR project that exposes some web services I also have a JAR
project that acts as a client application for the web services. The
client application makes http requests to the web services.

To run unit tests I need to set up a jetty server running the web
services.

I have tried the following

1) use the maven-dependency-plugin to extract the correct WAR from the
repository and copy it to sub directory in target.

2) use the maven-jetty-plugin to start a server running the WAR
downloaded in the previous step.  The server can be started before
running the unit tests and stopped when the tests have finished.

The jetty plugin is as follows


<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<stopPort>9966</stopPort>
<webApp>
${basedir}/target/iceCreamWar/ICECream.war
</webApp>
<stopKey>stop</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>stop-jetty</id>
<phase>prepare-package</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>

However if I run it I get the following error message

[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] Webapp source directory
C:\Workspace_MavenBuild\ICECreamClient\src\main\webapp does not exist

which is expected as the "run"goal assumes you have a normal web project
with a context.

If I change the goal to "run-war", then the jetty server does start for
the unit test, but only afterwoods. - the jetty documentation talks
about "Invokes the execution of the lifecycle phase package prior to
executing itself." which I presume is what is happening.

Any ideas how to get around this one?

Richard

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org