我有不同的服务模式文件(超过 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 文件以应用包详细信息。
请指教。
最佳答案
您需要定义一个以 .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中阅读更多相关信息。 .
关于java - Maven-xmlbeans : working with multiple schema files to generate a single jar file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30230481/