Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR trying to generate classes from a WSDL using maven in spring mvc

hi i'm trying to follow this example https://spring.io/guides/gs/consuming-web-service/ and i get the following error in my pom.xml file

this is my pom.xml file, the new part that i added is the part after the comment <-- WEB SERVICES -->

this is the part where is the problem :

<plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>       
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>hello.wsdl</generatePackage>
                    <forceRegenerate>true</forceRegenerate>
                    <schemas>
                        <schema>
                            <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                        </schema>
                    </schemas>
                </configuration>
            </plugin>

and here is the entire pom.xml

<?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>
    <groupId>com.pruebaWsCompany</groupId>
    <artifactId>app</artifactId>
    <name>PruebaWSproy</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                 </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>   

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>

        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>




        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>        
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>

            <!--WEB SERVICES -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>       
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>hello.wsdl</generatePackage>
                    <forceRegenerate>true</forceRegenerate>
                    <schemas>
                        <schema>
                            <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                        </schema>
                    </schemas>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

and this is the error that i get i try using maven update in my spring-tools suite IDE but still i get the same error

this is the error

Description Resource    Path    Location    Type
Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate: com/sun/codemodel/CodeWriter
-----------------------------------------------------
realm =    plugin>org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/d:/Users/myUser/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb2-plugin/0.12.3/maven-jaxb2-plugin-0.12.3.jar
urls[1] = file:/d:/Users/myUser/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb2-plugin-core/0.12.3/maven-jaxb2-plugin-core-0.12.3.jar
urls[2] = file:/d:/Users/myUser/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar
urls[3] = file:/d:/Users/myUser/.m2/repository/org/apache/commons/commons-lang3/3.2.1/commons-lang3-3.2.1.jar
urls[4] = file:/d:/Users/myUser/.m2/repository/com/sun/org/apache/xml/internal/resolver/20050927/resolver-20050927.jar
urls[5] = file:/d:/Users/myUser/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar
urls[6] = file:/d:/Users/myUser/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15.jar
urls[7] = file:/d:/Users/myUser/.m2/repository/org/jvnet/jaxb2/maven2/maven-jaxb22-plugin/0.12.3/maven-jaxb22-plugin-0.12.3.jar
urls[8] = file:/d:/Users/myUser/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.2.11/jaxb-runtime-2.2.11.jar
urls[9] = file:/d:/Users/myUser/.m2/repository/org/glassfish/jaxb/jaxb-xjc/2.2.11/jaxb-xjc-2.2.11.jar
urls[10] = file:/d:/Users/myUser/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2.jar
Number of foreign imports: 5
import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.DirectoryScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------
 (org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate:default:generate-sources)   pom.xml /PruebaWSproy   line 165    Maven Build Problem

+++EDIT

i used this tag at the start of my plugins tag and this tag at the end and i no longer have this problem Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate failed:

here is how i edited it

<build>
    <pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <additionalProjectnatures>
                    <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                </additionalProjectnatures>
                <additionalBuildcommands>
                    <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                </additionalBuildcommands>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArgument>-Xlint:all</compilerArgument>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <mainClass>org.test.int1.Main</mainClass>
            </configuration>
        </plugin>

        <!--WEB SERVICES -->

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>${project.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaLanguage>WSDL</schemaLanguage>
                <generatePackage>hello.wsdl</generatePackage>
                <forceRegenerate>true</forceRegenerate>
                <schemas>
                    <schema>
                        <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                    </schema>
                </schemas>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

but after i update my maven there are no new packages or classes, this should bring me new classess and packages right?

++++EDIT 2

i try putting this tags but stille no class are generated

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>1.12</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                        <schemaLanguage>WSDL</schemaLanguage>
                        <generateDirectory>D:/Users/myUser/Documents/workspace-sts-3.6.0.RELEASE/ProjectTryWSDL/src/gensrc</generateDirectory>
                        <generatePackage>com.wsdl.src</generatePackage>
                        <schemas>
                            <schema>
                                <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                            </schema>
                        </schemas>              
                        </configuration>
                    </execution>
                </executions>
            </plugin> 

i think that my folder have permissions to create folders by external apps, or do i need to create that folder by mysefl?

+++++ EDIT 3

i added this route in the generate tag

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxws-maven-plugin</artifactId>
                <version>1.12</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsimport</goal>
                        </goals>
                        <configuration>
                        <schemaLanguage>WSDL</schemaLanguage>
                        <generateDirectory>${project.build.sourceDirectory}/gensrc</generateDirectory>
                        <generatePackage>com.wsdl.src</generatePackage>
                        <schemas>
                            <schema>
                                <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                            </schema>
                        </schemas>              
                        </configuration>
                    </execution>
                </executions>
            </plugin> 

and this is my properties tags

<properties>
    <java-version>1.6</java-version>
    <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
    <org.aspectj-version>1.6.10</org.aspectj-version>
    <org.slf4j-version>1.6.6</org.slf4j-version>
    <project.version>0.12.3</project.version>
</properties>
like image 571
stackUser2000 Avatar asked Jan 08 '23 20:01

stackUser2000


2 Answers

Previously I have this issue because of the plugin version (I try to use 0.12.3)

Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate: com/sun/xml/bind/api/ ErrorListener

I don't know if the cause is the same or not but I fixed it by changing the version. Try this one:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <mainClass>org.test.int1.Main</mainClass>
            </configuration>
        </plugin>
         <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.12.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaLanguage>WSDL</schemaLanguage>
                <generatePackage>soap.servicereq1</generatePackage>
                <schemas>
                    <schema>    
                    <url>http://xxx/Services/ProxyService/ServiceRequest?wsdl</url>
                    </schema>
                </schemas>
            </configuration>
        </plugin>

Hope it works

like image 111
Irene Felita Avatar answered May 09 '23 08:05

Irene Felita


You need to change your configuration like below to generate sources.

generateDirectory is the actual directory where the source files are created.

generatePackage is the package name for the source files you generate from WSDL, so you should find these package sub-folders inside generateDirectory

      <configuration>
               <schemaLanguage>WSDL</schemaLanguage>
               <generateDirectory>${project.build.sourceDirectory}/gensrc
                      </generateDirectory>
               <generatePackage>com.wsdl.src</generatePackage>
                <schemas>
                    <schema>
                        <url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
                    </schema>
                </schemas>
       </configuration>

You can use mvn jaxb2:generate to generate source files inside your project/src/gensrc directory. For more details on possible configurations, have a look at this cheat sheet :)

like image 38
Arkantos Avatar answered May 09 '23 08:05

Arkantos