Maven - xmlbeans:使用多个模式文件生成单个jar文件

时间:2015-05-14 06:11:40

标签: java maven-3 xmlbeans-maven-plugin

我有不同的服务模式文件(超过5个),我想从中使用xmlbeans生成一个jar文件。

我正在使用xmlbean插件,如下所示

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xmlbeans-maven-plugin</artifactId>
        <version>${xmlbeans.version}</version>
        <executions>
            <execution>
                <goals>
                    <goal>xmlbeans</goal>
                </goals>
                <phase>compile</phase>
            </execution>
        </executions>
        <inherited>true</inherited>
        <configuration>
            <download>true</download>
            <javaSource>${java.version}</javaSource>
            <schemaDirectory>src/main/xsd</schemaDirectory>
            <xmlConfigs>
                <xmlConfig implementation="java.io.File">src/main/xsdconfig/xsdconfig.xml</xmlConfig>
            </xmlConfigs>
        </configuration>
    </plugin>
</plugins>

我想为不同的服务架构设置不同的包名称。如何指定提供架构路径的位置和位置以及xsdConfig文件以应用程序包详细信息。

请建议。

1 个答案:

答案 0 :(得分:2)

您需要定义以.xsdconfig结尾的文件(例如myConfig.xsdconfig),以将每个架构文件中的targetNamespace映射到Java包名称。将此.xsdconfig文件放在相同的目录中,作为您正在编译的相应.xsd文件。例如,假设您有以下.xsd文件:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
       targetNamespace="http://your.company.org/dileep">
    ...
</xs:schema>

然后,您将定义以下myConfig.xsdconfig文件,如下所示:

<!-- you must use the http://www.bea.com/2002/09/xbean/config namespace here -->
<xb:config xmlns:xb="http://www.bea.com/2002/09/xbean/config">
    <xb:namespace uri="http://your.company.org/dileep">   <!-- map this namespace -->
        <xb:package>org.company.your.dileep</xb:package>  <!-- to this Java package -->
    </xb:namespace>
    <!-- more namespace mappings can go here ... -->
</xb:config>

还可以控制从每个模式文件生成的Java类的名称。

您可以在official XMLBeans documentation

中详细了解相关信息