使用maven从其余WADL生成可序列化类

时间:2017-10-12 18:21:47

标签: java rest maven wadl

我需要使用maven插件从其余的WADL生成实现Serializable的类。我可以通过添加jaxb-bindings.xml来完成WSDL项目,但这对WADL项目不起作用。

修改 现在我在生成文件时遇到此错误

  

无法执行目标   org.apache.cxf:cxf-wadl2java-plugin:3.2.0:wadl2java(generate-sources)   on project my_project:java.lang.RuntimeException:编译错误   来自WADL的架构:   “http://localhost:8080/rest_web/rest/application.wadl”不是其中的一部分   这个汇编。这是一个错误   “http://localhost:8080/rest_web/rest/application.wadl/xsd2.xsd”? - >   [帮助1]

  1. 我发现我的标签位于错误的位置 客户所以我修好了。
  2. 我为-xjc-extension添加了extraarg,因为链接到oracle 来自此CXF issue
  3. 的文档
  4. 更新了我的jaxb-bindings.xml
  5. 生成WADL的web app pom.xml:

    <plugin>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>maven-wadl-plugin</artifactId>
        <version>1.19.4</version>
        <executions>
            <execution>
                <id>generate</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <phase>prepare-package</phase>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.7.25</version>
            </dependency>
            <dependency>
                <groupId>xerces</groupId>
                <artifactId>xercesImpl</artifactId>
                <version>2.11.0</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.9.1</version>
            </dependency>
        </dependencies>
        <configuration>
            <wadlFile>${project.build.outputDirectory}/application.wadl</wadlFile>
            <formatWadlFile>true</formatWadlFile>
            <baseUri>http://${server}:8080/${project.name}/rest</baseUri>
            <packagesResourceConfig>
                <param>webservice.rest</param>
            </packagesResourceConfig>
            <wadlGenerators>
                <wadlGeneratorDescription>
                    <className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc
                    </className>
                    <properties>
                        <property>
                            <name>applicationDocsFile</name>
                            <value>${basedir}/src/main/doc/application-doc.xml</value>
                        </property>
                    </properties>
                </wadlGeneratorDescription>
                <wadlGeneratorDescription>
                    <className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport</className>
                    <properties>
                        <property>
                            <name>grammarsFile</name>
                            <value>${basedir}/src/main/doc/application-grammars.xml</value>
                        </property>
                    </properties>
                </wadlGeneratorDescription>
            </wadlGenerators>
        </configuration>
    </plugin>
    

    客户端pom.xml文件:

    <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-wadl2java-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
            <execution>
                <id>generate-sources</id>
                <phase>generate-sources</phase>
                <configuration>
                    <sourceRoot>${basedir}/target/generated-sources</sourceRoot>
                    <wadlOptions>
                        <wadlOption>
                            <wadl>http://localhost:8080/rest_web/rest/application.wadl</wadl>
                            <extraargs>
                                <extraarg>-verbose</extraarg>
                                <extraarg>-xjc-extension</extraarg>
                            </extraargs>
                            <bindingFiles>
                                <bindingFile>${basedir}/src/main/resources/META-INF/jaxb/jaxb-bindings.xml</bindingFile>
                            </bindingFiles>
                            <packagename>org.apache.cxf.systest.jaxrs.codegen.service</packagename>
                            <schemaPackagenames>
                                <schemaPackagename>http://superbooks=org.apache.cxf.systest.jaxrs.codegen.schema</schemaPackagename>
                            </schemaPackagenames>
                        </wadlOption>
                    </wadlOptions>
                </configuration>
                <goals>
                    <goal>wadl2java</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    JAXB-bindings.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <bindings xmlns="http://java.sun.com/xml/ns/jaxb"
              xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
              xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
              xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
              version="2.1">
        <globalBindings>
            <serializable uid="1" />
        </globalBindings>
    </bindings> 
    

1 个答案:

答案 0 :(得分:0)

原因是您在<xs:schema>块中有多个XSD架构(导入的xsd文件或明确定义的<grammars>标签)。您需要在wadl中的<xs:schema>块中包含一个根<grammars>标记,才能使XJB绑定与wadl2java一起使用。我正在寻找没有wadl编辑的解决方法,但仍未成功,如果有人分享解决方案,我将非常感激。

最好的问候,Aliaksei