Hi Fredrik, I had a similar requirement to you but was still using the old xfire toolkit which is much the same as the new cxf web services. I decided to try and follow the recommended practice of having only 1 artifact produced by 1 module.
In order to do this i setup some annotated java web service classes in a 'web' module with a standard war packaging. In this module i added the java2wsdl task for generating the wsdl to be published live through the war deployment. I then set up a new module called 'client' which used a dependency on the 'web' module and the cargo plugin to automatically deploy the war as part of the build in an embedded jetty container which was then available tfor running the wsdl2java task for generating the client stub classes directy from the published (and auto-generated) wsdl. I then set the packaging of this client module to be a jar file which can then be referred to individually by any other modules or projects which are clients of the web service. Here's an example pom for the client module, hope this helps. The only issue i've found with this approach is that when you include the client module as a dependency it will also include the web module as it's a transitive dependency on the client module. Unfortunately it appears there is no way of include the war as a dependency o the plugin but i didn't investigate fully as i only use this internally within other modules in the same project and you can remove the transitive dependency through adding the <exclusion> in the dependency management section, not ideal if you plan to distribute through a repository but it works. cam ======================== <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- POM Identification --> <groupId>sample</groupId> <artifactId>client</artifactId> <packaging>jar</packaging> <version>0.1-SNAPSHOT</version> <name>Sample Client</name> <description>The Sample Web Services Client Module</description> <!-- Parent POM --> <parent> <groupId>sample</groupId> <artifactId>sample</artifactId> <version>0.1-SNAPSHOT</version> </parent> <!-- Profiles --> <profiles /> <!-- Properties --> <properties /> <!-- Project Dependancies --> <dependencies> <!-- Project Dependencies --> <dependency> <groupId>sample</groupId> <artifactId>web</artifactId> <type>war</type> </dependency> <!-- Compile Dependencies --> <dependency> <groupId>org.codehaus.xfire</groupId> <artifactId>xfire-java5</artifactId> </dependency> <dependency> <groupId>org.codehaus.xfire</groupId> <artifactId>xfire-jaxb2</artifactId> </dependency> <dependency> <groupId>org.codehaus.xfire</groupId> <artifactId>xfire-spring</artifactId> </dependency> </dependencies> <!-- Build Definition --> <build> <plugins> <!-- Cargo Plugin for Hosting the Web Services WSDL for build time --> <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <configuration> <wait>false</wait> <container> <containerId>jetty6x</containerId> <type>embedded</type> <log>${basedir}/target/jetty.log</log> </container> <configuration> <properties> <cargo.servlet.port>8180</cargo.servlet.port> </properties> <deployables> <deployable> <groupId>sample</groupId> <artifactId>web</artifactId> <type>war</type> <properties> <context>sample-web</context> </properties> <!-- Used to verify the site is ready --> <pingURL>http://localhost:8180/sample-web/</pingURL> <!-- <pingTimeout>120000</pingTimeout> --> </deployable> </deployables> </configuration> </configuration> <executions> <execution> <id>start-container</id> <phase>initialize</phase> <goals> <goal>start</goal> </goals> </execution> <execution> <id>stop-container</id> <phase>compile</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin> <!-- Generates the Client Stub classes for the Sample Web Service --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>xfire-maven-plugin</artifactId> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>wsgen</goal> </goals> </execution> </executions> <configuration> <package>com.sample.client</package> <profile /> <binding /> <ouputDirectory>src/main/java</ouputDirectory> <wsdls> <wsdl>http://localhost:8180/sample-web/services/SampleService?wsdl</wsdl> </wsdls> </configuration> </plugin> </plugins> </build> </project> On 9/5/07, Glen Mazza <[EMAIL PROTECTED]> wrote: > I'm unsure, but if I understand you correctly, you have control over > both the server and the client, but you seem to want to run wsdl2java > twice--once for the server, once for the client. > > I believe though you can have wsdl2java generate both server and client > code at once--they have a very high overlap, if I'm not mistaken. If > so, you can move the compile the wsdl2java results into a separate JAR > file, and have both your client and server code reference it via a > dependency. That would seem to be more robust and faster than running > wsdl2java twice. > > There is an issue, however, of files relevant for one but not the other. > If that is a major issue, perhaps creating two JAR files (one for > client, one for server) and specifying which parts are to be excluded > from both might work. At this stage, however, I'm still pretty much a > Maven newbie and am not certain how to proceed. > > HTH, > Glen > > Am Mittwoch, den 05.09.2007, 10:44 +0200 schrieb Fredrik Jonson: > > Hi, > > > > I posted the following on the maven mailing list, but maybe I was too > > much off topic there as I got no response. > > > > My question is, what's the best practice when it comes to setting up > > interdependency for a web service client project in Maven 2? > > > > I have a module that provides a web service, a maven war project using > > CXFServlet. In that module I generate a wsdl file using the java2wsdl > > target from the cxf-codegen-plugin. Works perfectly of course. > > > > Now, I want to set up a client module too. The client module is not > > strictly dependent on the jar of the service provider module, so it > > doesn't seem to be a normal dependency. > > > > I suppose could just copy the generated wsdl manually from the provider > > module somewhere into the client module src directory and generate > > classes with the wsdl2java target and build against that. This seems > > doable, but I'm wondering if there isn't a smarter way - I'm rather > > newbieish both to m2 and cxf so I would almost expect that I've missed > > some clever way to solve this. > > > > Any pointers greatfully appreciated! How do you people solve it? > > > >
