2012-12-12 82 views
11

我想使用jaxws maven插件爲我的Web服務客戶端生成源代碼並獲得以下異常;jaxws-maven-plugin 2.2 NoSuchMethodError失敗()

[ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:wsimport (default) on project cf-wsjavaclient: Error executing: wsimpor 
t [-keep, -s, C:\Users\sjunejo\Documents\GitHub\sandbox-ofsconnectorpoc\cf-wsjavaclient\target, -Xnocompile, http://localhost:9090/axis2/services/OFSC 
onnectorServiceWS?wsdl]: UndeclaredThrowableException: javax.xml.bind.annotation.XmlElementRef.required() -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.2:wsimport (default) on p 
roject cf-wsjavaclient: Error executing: wsimport [-keep, -s, C:\Users\sjunejo\Documents\GitHub\sandbox-ofsconnectorpoc\cf-wsjavaclient\target, -Xnoco 
mpile, http://localhost:9090/axis2/services/OFSConnectorServiceWS?wsdl] 
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217) 
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 
     at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 
     at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 
     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 
     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) 
     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 
     at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) 
     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) 
     at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     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.MojoExecutionException: Error executing: wsimport [-keep, -s, C:\Users\sjunejo\Documents\GitHub\sandbox-ofsconnecto 
rpoc\cf-wsjavaclient\target, -Xnocompile, http://localhost:9090/axis2/services/OFSConnectorServiceWS?wsdl] 
     at org.jvnet.jax_ws_commons.jaxws.WsImportMojo.wsImport(WsImportMojo.java:360) 
     at org.jvnet.jax_ws_commons.jaxws.WsImportMojo.processWsdlViaUrls(WsImportMojo.java:342) 
     at org.jvnet.jax_ws_commons.jaxws.WsImportMojo.execute(WsImportMojo.java:283) 
     at org.jvnet.jax_ws_commons.jaxws.MainWsImportMojo.execute(MainWsImportMojo.java:30) 
     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) 
     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 
     ... 19 more 
Caused by: java.lang.reflect.UndeclaredThrowableException 
     at $Proxy44.required(Unknown Source) 
     at com.sun.tools.xjc.generator.bean.field.AbstractField.annotateReference(AbstractField.java:192) 
     at com.sun.tools.xjc.generator.bean.field.AbstractField.annotate(AbstractField.java:161) 
     at com.sun.tools.xjc.generator.bean.field.AbstractFieldWithVar.createField(AbstractFieldWithVar.java:80) 
     at com.sun.tools.xjc.generator.bean.field.SingleField.<init>(SingleField.java:94) 
     at com.sun.tools.xjc.generator.bean.field.SingleField.<init>(SingleField.java:81) 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
     at com.sun.tools.xjc.generator.bean.field.GenericFieldRenderer.generate(GenericFieldRenderer.java:69) 
     at com.sun.tools.xjc.generator.bean.field.DefaultFieldRenderer.generate(DefaultFieldRenderer.java:82) 
     at com.sun.tools.xjc.generator.bean.BeanGenerator.generateFieldDecl(BeanGenerator.java:774) 
     at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassBody(BeanGenerator.java:555) 
     at com.sun.tools.xjc.generator.bean.BeanGenerator.<init>(BeanGenerator.java:258) 
     at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:166) 
     at com.sun.tools.xjc.model.Model.generateCode(Model.java:290) 
     at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:283) 
     at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:94) 
     at com.sun.tools.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:142) 
     at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2244) 
     at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:191) 
     at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:137) 
     at com.sun.tools.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:381) 
     at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:198) 
     at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:179) 
     at com.sun.tools.ws.WsImport.doMain(WsImport.java:74) 
     at org.jvnet.jax_ws_commons.jaxws.WsImportMojo.wsImport(WsImportMojo.java:357) 
     ... 24 more 
Caused by: java.lang.NoSuchMethodException: javax.xml.bind.annotation.XmlElementRef.required() 
     at java.lang.Class.getDeclaredMethod(Class.java:1937) 
     at com.sun.codemodel.TypedAnnotationWriter.invoke(TypedAnnotationWriter.java:112) 
     ... 52 more 

這是我用來構建項目的POM;

<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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.xxxxx</groupId> 
    <artifactId>cf-wsjavaclient</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>cf-wsjavaclient</name> 
    <properties> 
     <wsdlLoc>http://localhost:9090/axis2/services/OFSConnectorServiceWS?wsdl</wsdlLoc> 
     <skipTests>true</skipTests> 
    </properties> 
    <build> 
     <plugins> 
     <plugin> 
      <artifactId>maven-failsafe-plugin</artifactId> 
      <version>2.6</version> 
      <!-- Disable tests for now, until we have client jar built then we can run as follows; 
       To run the tests: 
       $ mvn verfiy -DskipTests=false 
      -->    
      <configuration> 
       <skipTests>${skipTests}</skipTests> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>integration-test</goal> 
         <goal>verify</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
      <plugin> 
       <groupId>org.jvnet.jax-ws-commons</groupId> 
       <artifactId>jaxws-maven-plugin</artifactId> 
       <version>2.2</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>wsimport</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <wsdlUrls> 
         <wsdlUrl>${wsdlLoc}</wsdlUrl> 
        </wsdlUrls> 
        <sourceDestDir>${basedir}/target</sourceDestDir> 
       </configuration> 
      </plugin> 
      <!-- Don't forget to use endorsed with JAX-WS 2.2 on Java 6 !! --> 
       <!-- plugin> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <compilerArguments> 
         <endorseddirs>${basedir}/endorsed</endorseddirs> 
         </compilerArguments> 
        </configuration> 
       </plugin--> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>com.sun.xml.ws</groupId> 
      <artifactId>jaxws-rt</artifactId> 
      <version>2.2.6</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.xml.bind</groupId> 
      <artifactId>jaxb-api</artifactId> 
      <version>2.2.5</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.2</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 

我試圖找到信息,但沒有可用的東西。能否請你幫忙。

感謝

-

Sjunejo最近,我有同樣的錯誤

+0

正如我試圖從$ JAVA_HOME/bin中調用的wsimport生成從簡單的Java類的源代碼和它的作品像一個魅力的一些信息.... – SJunejo

回答

14


看來,這是因爲的wsimport混亂與2.12.2版本JAXB的。

我可以通過編輯項目的pom.xml並添加<target>2.1</target>標籤給每個導入的WSDL的配置,這樣的正確生成Web服務來源:

<execution> 
    <goals> 
     <goal>wsimport</goal> 
    </goals> 
    <configuration> 
     <wsdlFiles> 
      <wsdlFile>path/to/file.wsdl</wsdlFile> 
     </wsdlFiles> 
     <wsdlLocation>http://path/to/webservice?wsdl</wsdlLocation> 
     <staleFile>path/to/file.stale</staleFile> 
     <target>2.1</target> 
    </configuration> 
    <id>wsimport-generate-WebServiceName</id> 
    <phase>generate-sources</phase> 
</execution> 

希望它可以幫助誰有這個問題。

+0

3小時後的嘗試,這是解決方案。以上都沒有奏效。 – UltraMaster

+1

這也適用於我。就我而言,這是一臺裝有Java 7的機器,另一臺裝有Java 6的機器增加了混亂。 – Jim

+2

又幫助我了!唉,互聯網現在是我的記憶。 – Jim

5

我假設你的問題是你正在Java 6上運行?由於Java 6包含JAX-WS的較早版本,因此如果要在Java 6上生成,編譯和運行JAX-WS 2.2,則必須重寫那些包含的API。正如Tex Killer上面提到的,您可以告訴wsimport生成JAX-WS 2.1對象和所有東西都應該可以正常工作(假設你有一個包含JAX-WS 2.1的Java 6 JRE,而不是2.0)。如果你特別希望產生2.2,不過,我可以通過我的POM設置爲以下(只包括了爲簡潔的構建元素)要做到這一點:

<build> 
    <plugins> 
     <!-- Generate client using WSDL --> 
     <plugin> 
      <groupId>org.jvnet.jax-ws-commons</groupId> 
      <artifactId>jaxws-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <goals> 
         <goal>wsimport</goal> 
        </goals> 
        <configuration> 
         <target>2.2</target> 
         <verbose>true</verbose> 
         <wsdlUrls> 
          <wsdlUrl>http://localhost:8080/axis2/services/HelloWorld?wsdl</wsdlUrl> 
         </wsdlUrls> 
         <packageName>my.package.name</packageName> 
        </configuration> 
       </execution> 
      </executions> 


      <!-- if you want to use a specific version of JAX-WS, you can do so like 
       this --> 
      <dependencies> 
       <dependency> 
        <groupId>com.sun.xml.ws</groupId> 
        <artifactId>jaxws-tools</artifactId> 
        <version>2.2.7</version> 
        <exclusions> 
         <exclusion> 
          <groupId>org.jvnet.staxex</groupId> 
          <artifactId>stax-ex</artifactId> 
         </exclusion> 
        </exclusions> 
       </dependency> 
       <dependency> 
        <groupId>org.jvnet.staxex</groupId> 
        <artifactId>stax-ex</artifactId> 
        <version>1.7</version> 
        <exclusions> 
         <exclusion> 
          <groupId>javax.xml.stream</groupId> 
          <artifactId>stax-api</artifactId> 
         </exclusion> 
        </exclusions> 
       </dependency> 
      </dependencies> 
     </plugin> 

     <!-- Don't forget to use endorsed with JAX-WS 2.2 on Java 6 !! --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.3</version> 
      <executions> 
       <execution> 
        <phase>validate</phase> 
        <goals> 
         <goal>copy</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>${project.build.directory}/endorsed</outputDirectory> 
         <silent>true</silent> 
         <artifactItems> 
          <artifactItem> 
           <groupId>javax.xml.bind</groupId> 
           <artifactId>jaxb-api</artifactId> 
           <version>2.2.4</version> 
           <type>jar</type> 
          </artifactItem> 
          <artifactItem> 
           <groupId>javax.xml.ws</groupId> 
           <artifactId>jaxws-api</artifactId> 
           <version>2.2.8</version> 
           <type>jar</type> 
          </artifactItem> 
         </artifactItems> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
       <compilerArguments> 
        <endorseddirs>${project.build.directory}/endorsed</endorseddirs> 
       </compilerArguments> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

有三個變化我認爲你需要在你的POM中完成這項工作。我從這裏得到的所有三個:http://jax-ws-commons.java.net/jaxws-maven-plugin/usage.html。首先,您可能需要像上面那樣添加jaxws插件的其他依賴項。另外請注意,您將不得不取消對maven-compiler-plugin的註釋,但似乎已正確設置了認可的目錄。第三,你需要添加maven-dependency-plugin的定義。您可能需要修改JAXB和JAX-WS API版本以滿足您的需求。

除了這些,我只好再更新了下< java主>與認可庫推出的Maven通過將罐的JAXB和JAX-WS API(POM中定義相同的)的JRE/LIB /認可。最後,確保剛剛更新的JRE正在啓動Maven構建。如果它仍然無法正常工作,請檢查Maven構建的Eclipse運行配置,並確保它使用的是帶有背書庫的JRE。 (在我的情況下,運行配置使用的是與項目配置不同的JRE - 我更新了項目JRE,但沒有運行配置使用的JRE,並且花了我大約一天的時間來弄清爲什麼它仍然不是加工)。

這應該爲你做的伎倆。如果你想對它更精通一點,你可以更新運行配置,直接引用外部支持的庫,以防你不想修改你的JRE安裝。

歡呼

相關問題