Apache CXF codegen 插件抛出空指针

发布于 2024-10-07 07:26:24 字数 6242 浏览 1 评论 0原文

我使用 maven 从 wsdl 合约生成代码,但是当执行目标generate-sources 时,我在 WSDL2JavaMojo 中得到一个空指针。 processWsdl 方法似乎正在尝试使用引用 (outputDir),该引用为 null。由于无法理解为什么会有这个空指针问题,我的 pom 文件看起来没问题。

如果我将 codegen 插件的版本更改为 2.2.1,我仍然会收到错误,但代码已生成,因此我可以将其从 target/ generated-sources 复制到另一个位置。但我想避免构建失败。

这是我的 pom 和 stacktrace,谢谢。

偶来

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

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] 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

浮云落日 2024-10-14 07:26:24

如果您在扩展堆栈跟踪中搜索并找到以下代码行:

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)

那么这可能会发生,因为您有这样的语句:

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

在您的 wsdl 或 xsd 中的某处...但您可能并不真正拥有/需要 命名空间 并且该属性只需要删除,如下所示:

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

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" />
一绘本一梦想 2024-10-14 07:26:24

尝试将其添加为配置:

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

Try adding this as a configuration:

<wsdlOptions><wsdl>${basedir}/src/main/resources/wsdl/myWsdl.wsdl</wsdl></wsdlOptions>
还给你自由 2024-10-14 07:26:24

以下是 WSDL2JavaMojo 的代码。第 297 行抛出 NullPointerException,因此它一定是您的 sourceRoot 的问题。

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

尝试删除 sourceRoot 并查看源是否在默认位置 (target/ generated-sources/cxf) 中生成。或者尝试将您的 sourceRoot 更改为其他内容(例如 /tmp)。如果有效,则您使用的值有问题:${basedir}/target/ generated-sources/

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/

软的没边 2024-10-14 07:26:24

好吧,2.2.1 和 2.1.2 都是古老的并且目前不受支持。自这两个事件以来,已经进行了很多修复。我绝对建议尝试使用 2.3.1 并看看它是否至少已修复。

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.

忱杏 2024-10-14 07:26:24

似乎您遇到了 https://issues.apache.org/jira/browse/ CXF-2201

下次您遇到此类问题时,您可以考虑在 CXF 的留言板上发布相关信息,或搜索他们的 JIRA。我通过谷歌搜索“WSDL2JavaMojo NullPointerException”很快发现了这个错误

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文