简体   繁体   English

无法从wsdl文件生成Java代码

[英]Cant generate java code from wsdl file

First I created simple web service with java and then generated wsdl for that web service and tested with SoapUI so it works fine. 首先,我使用Java创建了简单的Web服务,然后为该Web服务生成了wsdl,并使用SoapUI进行了测试,使其工作正常。 After that now I am tring to generate java classes from wsdl file which was generated previously. 在那之后,现在我正尝试从先前生成的wsdl文件生成Java类。

Here is the my pom.xml file configuration. 这是我的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>

When I tried to generate it I am getting error like this. 当我尝试生成它时,出现这样的错误。

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

So I dont understed what is this - source 5 thing is ? 所以我没有低估这是什么5件事是什么?

Update :According to @Simze's answer above error is disappeared. 更新 :根据@Simze的回答,以上错误消失了。 Now I am geeting this error. 现在我正在解决这个错误。

    [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 file wsdl文件

Finally found the solution for this. 终于找到了解决方案。 When we are generating java code for given wsdl file we need to specify what are to be generated in the configuration section of cxf-codegen-plugin 在为给定的wsdl文件生成Java代码时,我们需要在cxf-codegen-plugin的配置部分中指定要生成的内容

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

Here -impl means this will generate the service implementation class and -server is used to generate server component which can be used to publich the service. 在这里, -impl表示这将生成服务实现类,并且-server用于生成可用于公开服务的服务器组件。

The error you're getting because, you're trying to run maven under Java 1.3, which doesn't support annotations. 因为您正在尝试在不支持注释的Java 1.3下运行Maven而遇到了错误。 Please add below tags under <build> element which will solve your problem. 请在<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>

You need to use Java 1.5 or higher. 您需要使用Java 1.5或更高版本。 This is what the compiler error is telling you when it says - source 5 thing because annotation support was added to Java from Java 1.5 onwards. 这就是编译器错误告诉您的内容-源代码5,因为注释支持是从Java 1.5开始添加到Java的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM