Generate source using jaxb from an xsd that is in my classpath

岁酱吖の 提交于 2019-12-10 18:17:42

问题


I'm trying to generate java classes using JAXB from a schema in my class path. For CXF I generated java classes from a wsdl in my classpath like so:

<wsdlOptions>
    <wsdlOption>
        <wsdl>classpath:wsdl/MetsInterfaceService.wsdl</wsdl>
    </wsdlOption>
</wsdlOptions>

I was hoping something similar existed with JAXB. I did try using a catalog but this seems to be more in line when a schema (stored in the same maven module) imports another schema in the classpath.

Any help would be appreciated! -Sal


回答1:


The CXF XJC Maven Plugin appears to support classpath:.

The XsdOption object is used to pass specific options and configuration for each XSD file that is to be processed.

The example on the site shows classpath: used in several ways in <xsdOption> paths for <xsd>, <bindingFile>, and <catalog> paths:

<configuration>
    <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
    <xsdOptions>
        <xsdOption>
            <xsd>classpath:/schemas/wsdl/http.xsd</xsd>
            <bindingFile>classpath:/schemas/wsdl/http.xjb</bindingFile>
            <catalog>${basedir}/src/main/build-resources/catalog.cat</catalog>
        </xsdOption>
        <xsdOption>
            <xsd>classpath:/schemas/wsdl/ws-addr.xsd</xsd>
            <packagename>org.apache.cxf.ws.addressing</packagename>
        </xsdOption>
        <xsdOption>
            <xsd>classpath:/schemas/wsdl/addressing.xsd</xsd>
            <bindingFile>classpath:/schemas/wsdl/addressing.xjb</bindingFile>
        </xsdOption>
        <xsdOption>
            <xsd>classpath:/schemas/configuration/security.xsd</xsd>
            <bindingFile>classpath:/schemas/configuration/security.xjb</bindingFile>
            <catalog>${basedir}/src/main/build-resources/catalog.cat</catalog>
            <extensionArgs>
                <extensionArg>-Xdv</extensionArg>
            </extensionArgs>
        </xsdOption>
        <xsdOption>
            <xsd>classpath:/schemas/wsdl/ws-addr-wsdl.xsd</xsd>
            <bindingFile>classpath:/schemas/wsdl/ws-addr-wsdl.xjb</bindingFile>
            <extension>true</extension>
        </xsdOption>
        <xsdOption>
            <xsd>classpath:/schemas/wsdl/addressing200403.xsd</xsd>
            <bindingFile>classpath:/schemas/wsdl/addressing200403.xjb</bindingFile>
        </xsdOption>
    </xsdOptions>
</configuration>


来源:https://stackoverflow.com/questions/12307396/generate-source-using-jaxb-from-an-xsd-that-is-in-my-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!