2015-10-20 63 views
0

首先,我使用java創建了簡單的Web服務,然後爲該Web服務生成了wsdl並使用SoapUI進行了測試,因此工作正常。之後,現在我正在從之前生成的wsdl文件生成java類。無法從wsdl文件生成java代碼

這是我的pom.xml文件配置。

<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"> 
     <parent> 
      <artifactId>webService</artifactId> 
      <groupId>WebService</groupId> 
      <version>1.0-SNAPSHOT</version> 
     </parent> 
     <modelVersion>4.0.0</modelVersion> 

     <artifactId>contractFirst</artifactId> 
     <packaging>jar</packaging> 

     <name>contractFirst</name> 
     <url>http://maven.apache.org</url> 

     <properties> 
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
      <cxf.version>2.2.3</cxf.version> 
     </properties> 
     <build> 
      <!-- Generate Java classes from WSDL during build --> 
      <plugins> 
      <plugin> 
       <groupId>org.apache.cxf</groupId> 
       <artifactId>cxf-codegen-plugin</artifactId> 
       <version>${cxf.version}</version> 
       <executions> 
        <execution> 
         <id>generate-sources</id> 
         <phase>generate-sources</phase> 
         <configuration> 
          <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot> 
          <wsdlOptions> 
           <wsdlOption> 
            <wsdl>${basedir}/src/main/resources/OrderProcess.wsdl</wsdl> 
            <extraargs> 
             <extraarg>-server</extraarg> 
            </extraargs> 
           </wsdlOption> 
          </wsdlOptions> 
         </configuration> 
         <goals> 
          <goal>wsdl2java</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <!-- Add generated sources - avoids having to copy generated sources to build location --> 
      <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/src/main/java</source> 
          </sources> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <!-- Build the JAR with dependencies --> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <configuration> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
       </configuration> 
      </plugin> 
     </plugins> 

     </build> 


    </project> 

當我試圖生成它時,我得到這樣的錯誤。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project contractFirst: Compilation failure: Compilation failure: 
    [ERROR] /home/contractFirst/target/generated/src/main/java/demo/order/OrderProcessService.java:[24,1] error: annotations are not supported in -source 1.3 
    [ERROR] 
    [ERROR] (use -source 5 or higher to enable annotations) 
    [ERROR] /home/contractFirst/target/generated/src/main/java/demo/order/OrderProcessService.java:[73,61] error: variable-arity methods are not supported in -source 1.3 
    [ERROR] 
    [ERROR] (use -source 5 or higher to enable variable-arity methods) 
    [ERROR] /home/contractFirst/target/generated/src/main/java/demo/order/ProcessOrderResponse.java:[29,1] error: annotations are not supported in -source 1.3 
    [ERROR] 
    [ERROR] (use -source 5 or higher to enable annotations) 
    [ERROR] /home/contractFirst/target/generated/src/main/java/demo/order/ObjectFactory.java:[24,1] error: annotations are not supported in -source 1.3 
    [ERROR] 
    [ERROR] (use -source 5 or higher to enable annotations) 
    [ERROR] /home/contractFirst/target/generated/src/main/java/demo/order/ObjectFactory.java:[66,22] error: generics are not supported in -source 1.3 
    [ERROR] 
    [ERROR] (use -source 5 or higher to enable generics) 
    [ERROR] /home/contractFirst/target/generated/src/main/java/demo/order/Order.java:[31,1] error: annotations are not supported in -source 1.3 
    [ERROR] 
    [ERROR] (use -source 5 or higher to enable annotations) 
    [ERROR] /home/contractFirst/target/generated/src/main/java/demo/order/ProcessOrder.java:[28,1] error: annotations are not supported in -source 1.3 
    [ERROR] 

,所以我不understed這是什麼- 源5的事情是?

更新:根據@ Simze的回答,上面的錯誤消失了。現在我正在將這個錯誤彙總起來。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project contractFirst: Compilation failure 
    [ERROR] /home/contractFirst/target/generated/src/main/java/demo/order/OrderProcess_OrderProcessPort_Server.java:[17,34] cannot find symbol 
    [ERROR] symbol: class OrderProcessImpl 
    [ERROR] location: class demo.order.OrderProcess_OrderProcessPort_Server 
    [ERROR] -> [Help 1] 
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project contractFirst: Compilation failure 
    /home/contractFirst/target/generated/src/main/java/demo/order/OrderProcess_OrderProcessPort_Server.java:[17,34] cannot find symbol 
     symbol: class OrderProcessImpl 
     location: class demo.order.OrderProcess_OrderProcessPort_Server 

wsdl文件

+0

你正在使用哪個版本的maven? –

+0

我正在使用maven 3.0.5和java 1.7 – GPrathap

+0

您是否正確設置了JAVA_HOME? –

回答

0

你得到,因爲該錯誤,你想的Java 1.3,它不支持註解下運行Maven。請在<build>元素下添加下面的標籤,以解決您的問題。

<plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.0</version> 
     <configuration> 
     <source>1.7</source> 
     <target>1.7</target> 
     </configuration> 
    </plugin> 
</plugins> 
+0

添加此插件後,以前的錯誤消失。但我得到了另一個錯誤。更新後的問題 – GPrathap

+0

然後你需要發佈正確的代碼來解決這個問題?你是否宣佈了這個變量? –

+0

我應該添加wsdl文件嗎? – GPrathap

0

您需要使用Java 1.5或更高版本。這就是編譯器錯誤告訴你什麼時候說的 - 源碼5的東西,因爲從Java 1.5開始向Java添加了註釋支持。

1

終於找到了解決方案。 當我們給定的WSDL文件生成Java代碼,我們需要指定什麼在CXF-CODEGEN-插件的配置部分中產生

... 
    <wsdlOptions> 
    <wsdlOption> 
     <wsdl>${basedir}/src/main/resources/OrderProcess.wsdl</wsdl> 
     <extraargs> 
      <extrrg>-impl</extrrg> 
      <extrrg>-server</extrrg> 
     </extraargs> 
    </wsdlOption> 
    </wsdlOptions> 
..... 

這裏-impl意味着這將生成服務實現類和-server用於生成可用於公佈該服務的服務器組件。