You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Fredrik Jonson <fr...@myrealbox.com> on 2007/09/05 10:44:56 UTC

Setting up CXF client projects with Maven

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?

-- 
Fredrik Jonson

Re: Setting up CXF client projects with Maven

Posted by Fredrik Jonson <fr...@myrealbox.com>.
On 2007-09-05 at 11:30, glen.mazza@verizon.net 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.

Sorry for being unclear. I didn't mean that I wanted to do that, I was
more kind of trying to figure out if that was the proper way to do it.

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

Thanks, maybe I'll explore that option. For now I've actually set up my
multi module project like I mentioned in the original email - I generate
a wsdl in the service provider, and manually copy over that file to the
directory src/main/wsdl in the consumer module. Then I let wsdl2code
generate stubs in the consumer module. That way I'm certain that no
classes unrelated to the public service sneaks into the consumer
interface. Also, when (not if) I change the provider interface somewhere
down the line, I'm guaranteed that the consumer will whine loudly when
trying to use the old api (if it's non-compatible).

Apart from the overhead of configuring the maven incubator plugin
repository, and my messy approach of trial and error before I finally
figured out which (20+!) dependencies I needed include in the client
assembly, it worked out pretty well in the end.

Looking forward to the day CXF gets out of incubation. 8)

cheers
--
Fredrik Jonson

Re: Setting up CXF client projects with Maven

Posted by Cameron Jones <cm...@gmail.com>.
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 <gl...@verizon.net> 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?
> >
>
>

Re: Setting up CXF client projects with Maven

Posted by Glen Mazza <gl...@verizon.net>.
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?
>