Announcement Announcement Module
Collapse
No announcement yet.
Anyone migrate 'wsimport' into pom.xml's maven-antrun-plugin??? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Anyone migrate 'wsimport' into pom.xml's maven-antrun-plugin???

    I'm using a JAX-WS client for my Spring-WS app. I modeled my use of Jax-WS on the 'airilne' sample's jaxws client and, therefore, run the 'wsimport' generation of client sources from a standalone Ant build file.

    I'd like to migrate that 'wsimport' Ant task into my pom.xml file so that I can 'generate-sources', client artifacts and unit tests from the same place.

    However, when I migrate the "Mavenified" build.xml file over to plain old Ant 'generate-client-sources.xml' build file, I cannot seem to get addressability to any of the built-in Maven classpath variables. I get several variations on the "Reference maven.plugin.classpath not found." error message depending on whether I'm trying to use the 'maven.compile.classpath', 'maven.plugin.classpath', 'maven.test.classpath',... (with corresponding changes to the <dependencies> of course!)

    Here is an example of my attempt to get the plugin's variation working.

    Here is the Ant file I'm trying to run under Maven 2.0.5:
    Code:
    <?xml version="1.0"?>
    <project name="jaxws-client-targets" default="generate-client-sources">
        <property name="target.dir" value="target"/>
    
        <target name="init"
                description="Set up environ for 'wsimport' generate-sources.">
            <mkdir dir="${target.dir}/classes"/>
            <mkdir dir="${target.dir}/generated-sources/main/java"/>
        </target>
    
        <target name="generate-client-sources" depends="clean,init">
            <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport"
                     classpathref="maven.plugin.classpath"/>
            <wsimport wsdl="${basedir}/src/main/webapp/testapp.wsdl"
                      destdir="${target.dir}/classes"
                      package="com.testapp.ws.client"
                      verbose="true"
                      keep="true"
                      sourceDestDir="${target.dir}/generated-sources/main/java"/>
        </target>
    
        <target name="clean">
            <delete dir="${target.dir}/classes/com/testapp/ws/client"/>
            <delete dir="${target.dir}/generated-sources/main/java/com/testapp/ws/client"/>
        </target>
    
    </project>
    using the 'maven.plugin.classpath' as described on the maven-antrun-plugin webpage, and modify the pom.xml file accordingly:
    Code:
        <build>
            ...
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>generate-sources</phase>
                            <configuration>
                                <tasks>
                                    <ant antfile="${basedir}/generate-client-sources.xml"
                                         inheritRefs="true">
                                        <target name="generate-client-sources"/>
                                    </ant>
                                </tasks>
                                <sourceRoot>${project.build.directory}/generated-sources/main/java</sourceRoot>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>com.sun.xml.ws</groupId>
                            <artifactId>jaxws-tools</artifactId>
                            <version>EA3</version>
                        </dependency>
                        <dependency>
                            <groupId>com.sun.xml.bind</groupId>
                            <artifactId>jaxb-xjc</artifactId>
                            <version>2.1-EA2</version>
                        </dependency>
                        <dependency>
                            <groupId>com.sun.xml.stream.buffer</groupId>
                            <artifactId>streambuffer</artifactId>
                            <version>0.3</version>
                        </dependency>
                        <dependency>
                            <groupId>com.sun.xml.stream<groupId>
                            <artifactId>sjsxp</artifactId>
                            <version>1.0</version>
                        </dependency>
                        <dependency>
                            <groupId>org.jvnet.staxex</groupId>
                            <artifactId>stax-ex</artifactId>
                            <version>1.0</version>
                         </dependency>
                         <dependency>
                            <groupId>com.sun.xml.messaging.saaj</groupId>
                            <artifactId>saaj-impl</artifactId>
                            <version>1.3</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    Note that I've migrated the artifacts from the original Ant file's:
    Code:
    <artifact:dependencies pathId="generate.classpath">
    to 'dependencies' under the <plugin>.

    When I run this, I get that 'maven.plugin.classpath' is not found:
    Code:
    [DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-antrun-plugin:1.1:run' -->
    [DEBUG]   (f) artifacts = [ant:ant:jar:1.6.5:runtime,ant:ant-launcher:jar:1.6.5:runtime,org.apache.maven:maven-project:jar:2.0.1:runti
    [DEBUG]   (f) project = org.apache.maven.project.MavenProject@a8612a94
    [DEBUG]   (f) sourceRoot = /home/corbag/svn/testapp/webservices/target/generated-sources/main/java
    [DEBUG]   (f) tasks = 
    [DEBUG] -- end configuration --
    [INFO] [antrun:run {execution: generate-client-sources}]
    [INFO] Executing tasks
    [DEBUG] getProperty(ns=null, name=ant.reuse.loader, user=false)
    [DEBUG] getProperty(ns=null, name=ant.executor.class, user=false)
    [DEBUG] getProperty(ns=null, name=ant.file, user=false)
    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] Error executing ant tasks
    
    Embedded error: The following error occurred while executing this line:
    /home/corbag/svn/testapp/webservices/generate-client-sources.xml:5:
    Reference maven.plugin.classpath not found.
    [INFO] -----------------------------------------------------------------------
    [DEBUG] Trace org.apache.maven.lifecycle.LifecycleExecutionException: Error executing ant tasks
    and when I try the bug workaround (reassign the 'maven.plugin.classpath' variable to an Ant file property), I get the same problem.

    Has anyone been successful in getting the 'wsimport' Ant task to work under Maven? If so, can you post some working snippets? TIA.

  • #2
    Solution/Work-around found

    I ended up having to actually MOVE the <target> code from the Ant file into the pom.xml file in order to have the maven.compile.classpath be recognized. I guess that's a feature...?

    Here's the pom.xml snippet that performs the 'wsimport':
    Code:
    ...
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>generate-sources</phase>
                            <configuration>
                                <tasks>
                                    <property name="target.dir" value="target"/>
    
                                    <delete dir="${target.dir}/classes/com/testapp/ws/client"/>
                                    <delete dir="${target.dir}/generated-sources/main/java/com/testapp/ws/client"/>
    
                                    <mkdir dir="${target.dir}/classes"/>
                                    <mkdir dir="${target.dir}/generated-sources/main/java"/>
    
                                    <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport"
                                             classpathref="maven.compile.classpath"/>
                                    <wsimport wsdl="${basedir}/../webservices/src/main/webapp/testapp.wsdl"
                                              destdir="${target.dir}/classes"
                                              package="com.testapp.ws.client"
                                              verbose="true"
                                              keep="true"
                                              sourceDestDir="${target.dir}/generated-sources/main/java"/>
                                </tasks>
                                <sourceRoot>${project.build.directory}/generated-sources/main/java</sourceRoot>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    ...
    with the <dependencies> as listed in the previous post.

    This generates the JAX-WS client code correctly. The downside of this approach is that the Maven2 documentation strongly recommends using an external Ant file instead of embedding that <target> Ant code inside the pom.xml. Oh well.

    Anyone find a cleaner solution?

    Comment


    • #3
      I don't like to point out the obvious, but have you tried the JAX-WS Maven2 plugin? See https://jax-ws-commons.dev.java.net/jaxws-maven-plugin/

      Comment


      • #4
        Maybe I'm confused as to the versions being used. I thought you said that JAXB1 wasn't supported by any known Maven plugin:

        UnsupportedOperationException in Jaxb1Marshaller.initJaxbUnmarshaller

        Comment


        • #5
          Now I'm confused as well: I thought you were talking about building a JAX-WS client. I meant that you can use the JAX-WS maven2 plugin on the client-side.

          Comment


          • #6
            No, you're right. I have been suffering from the version dissonance between the airline server and the clients. :-/ I will try out the JAX-WS plugin.

            BTW, what were your reasons for using a back-level of the JAXB libraries for the server side of the airline sample? Why not just use the latest and greatest libs?

            Comment


            • #7
              Simple: when I wrote the airline sample, JAX-WS 2 was not out yet . I'm working on a new version of the airline sample, though, using JAXB2 instead of JAXB1, JPA instead of Hibernate, and also use the new Spring-WS annotations.

              Comment


              • #8
                Originally posted by Arjen Poutsma View Post
                Simple: when I wrote the airline sample, JAX-WS 2 was not out yet . I'm working on a new version of the airline sample, though, using JAXB2 instead of JAXB1, JPA instead of Hibernate, and also use the new Spring-WS annotations.
                That would be great!

                I just plugged the jaxws-maven-plugin into my pom.xml and voilą! It works. Much easier. Thanks!

                The next time I'm tempted to use the maven-antrun-plugin, someone please shoot me!

                Comment

                Working...
                X