开发者

Apache CXF codegen plugin throws nullpointer

I'm using maven to generate code from a wsdl contract, but when the goal generate-sources is executed I get a nullpointer in WSDL2JavaMojo. It seems like the method processWsdl is trying to use a reference (outputDir), which is null. By can't understand why have this nullpointer problem, my pom-file looks okay to me.

If I change the version of the codegen plugin to 2.2.1 I still get the error but the code is generated, so I can copy it from target/generated-sources to another location. But I want to avoid my build failures.

Here is my pom and stacktrace, thanks.

Olle

    <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>example.ws</groupId>
 <artifactId>ws-test</artifactId>
 <version>ws-test-1.0</version>

 <dependencies>
  <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>2.1.2</version>
        </dependency>

  <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-api</artifactId>
   <version>1.5.2</version>
  </dependency>
  <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version>1.5.2</version>
  </dependency>

 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf开发者_如何转开发-codegen-plugin</artifactId>
    <version>2.2.1</version>
    <executions>
     <execution>
      <id>generate-sources</id>
      <phase>generate-sources</phase>
      <configuration> 
       <sourceRoot>${basedir}/target/generated-sources/</sourceRoot>
       <wsdlOptions>
        <wsdlOption>
         <wsdl>${basedir}/src/main/java/Weather.wsdl</wsdl>
         <extraargs>
          <extraarg>-client</extraarg>
          <extraarg>-verbose</extraarg> 
         </extraargs>          
        </wsdlOption>
       </wsdlOptions>
      </configuration>
      <goals>
       <goal>wsdl2java</goal>
      </goals>
     </execution>
    </executions>    
   </plugin>
   <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
     <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
     </descriptorRefs>
    </configuration>
   </plugin>
   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
     <execution>
      <id>add-source</id>
      <phase>generate-sources</phase>
      <goals>
       <goal>add-source</goal>
      </goals>
      <configuration>
       <sources>
        <source>${basedir}/target/generated-sources</source>
       </sources>
      </configuration>
     </execution>
    </executions>
   </plugin>

  </plugins>

  <pluginManagement>
   <plugins>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <configuration>
      <source>1.5</source>
      <target>1.5</target>
     </configuration>
    </plugin>
   </plugins>
  </pluginManagement>
 </build>

    [ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.2.1:wsdl2java (generate-sources) on project ws-test: Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:2.2.1:wsdl2java failed. NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.2.1:wsdl2java (generate-sources) on project ws-test: Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:2.2.1:wsdl2java failed.
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:593)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:324)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:247)
 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:104)
 at org.apache.maven.cli.MavenCli.execute(MavenCli.java:427)
 at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:157)
 at org.apache.maven.cli.MavenCli.main(MavenCli.java:121)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
 at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
 at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:2.2.1:wsdl2java failed.
 at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:114)
 at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:577)
 ... 14 more
Caused by: java.lang.NullPointerException
 at org.apache.cxf.maven_plugin.WSDL2JavaMojo.processWsdl(WSDL2JavaMojo.java:297)
 at org.apache.cxf.maven_plugin.WSDL2JavaMojo.execute(WSDL2JavaMojo.java:257)
 at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:105)
 ... 15 more
[ERROR] 


If you search and find the following lines of code in your extended stack trace:

Caused by: org.apache.cxf.tools.common.ToolException: java.lang.NullPointerException
    at org.apache.cxf.tools.validator.internal.WSDLRefValidator.processSchemas(WSDLRefValidator.java:133)
...
Caused by: java.lang.NullPointerException
    at org.apache.ws.commons.schema.SchemaBuilder$1.validate(SchemaBuilder.java:524)

Then this could be happening because you have a statement like:

<xsd:import namespace="http://blah.com/" schemaLocation="mySchema.xsd" />

somewhere in your wsdl or xsd ... but you may not really have/need a namespace and that attribute just needs to be removed, like so:

<xsd:import schemaLocation="mySchema.xsd" />


Try adding this as a configuration:

<wsdlOptions><wsdl>${basedir}/src/main/resources/wsdl/myWsdl.wsdl</wsdl></wsdlOptions>


Here is the code for WSDL2JavaMojo. Line 297, throws a NullPointerException so it must be a problem with your sourceRoot.

294 private void processWsdl(WsdlOption wsdlOption) throws MojoExecutionException {
295
296     File outputDirFile = wsdlOption.getOutputDir();
297     outputDirFile.mkdirs();

Try removing sourceRoot and see if the sources are generated in the default location (target/generated-sources/cxf). Or try changing your sourceRoot to something else (e.g. /tmp). If that works then there is a problem with the value you are using: ${basedir}/target/generated-sources/


Well, both 2.2.1 and 2.1.2 are ANCIENT and unsupported at this point. A lot of fixes have gone in since either of those. I would definitely suggest trying with 2.3.1 and seeing if it's at least fixed.


It seems like you are running into https://issues.apache.org/jira/browse/CXF-2201

Next time you have an issue like this, you might consider posting about it on CXF's message boards, or searching their JIRA. I found this bug pretty quickly by googling "WSDL2JavaMojo NullPointerException"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜