我需要为 maven xmlbean 插件设置类路径,因为 xsd 取决于我的 2 java 程序,我不希望将其打包为 jar 并将其添加到依赖项中。
注意:我不希望使用 maven ant 插件来完成上述任务。
maven-xml 插件抛出的实际错误:
error: cvc-complex-type.2.4a: Expected elements 'namespace@http://xml.apache.org/xmlbeans/2004/02/xbean/config qname@http://xml.apache.org/xmlbeans/2004/02/xbean/config extension@http://xml.apache.org/xmlbeans/2004/02/xbean/config' instead of 'usertype@http://xml.apache.org/xmlbeans/2004/02/xbean/config' here in element config @http://xml.apache.org/xmlbeans/2004/02/xbean/config
由于我在 xmlconfig 中使用了 2 个用户类型,并且我有点用户 maven-xmlplugin 无法找到这些类。我什至尝试打包这些类并添加依赖项,但失败了。
pom.xml
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>myartifacts</artifactId>
<version>V1</version>
<packaging>jar</packaging>
<name>myartifacts</name>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<id>generateEbpacObjectMapJar</id>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
<configuration>
<memoryInitialSize>50m</memoryInitialSize>
<memoryMaximumSize>80m</memoryMaximumSize>
<schemaDirectory>src/xsddir</schemaDirectory>
<xmlConfigs>
<xmlConfig implementation="java.io.File">src/myconfig.xsdconfig</xmlConfig>
</xmlConfigs>
<sourceGenerationDirectory>target/generated/JARSources</sourceGenerationDirectory>
<debug>true</debug>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon</artifactId>
<version>8.7</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans-xpath</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans-xmlpublic</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans-qname</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
xsd 配置如下:
xb:config
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config"
xmlns:ebpac="http://bct.com/platform/factory"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xml.apache.org/xmlbeans/2004/02/xbean/config xmlconfig.xsd">
<xb:usertype name="cl:myClass" javaname="java.lang.Class">
<xb:staticHandler>com.ImplClassHandler</xb:staticHandler>
</xb:usertype>