我需要为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个usertype,并且我是位用户,所以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>发布于 2013-09-26 18:35:24
您可以在Maven depedency中查看<scope>provided</scope>标记的使用情况,jars将在编译时从您的.m2目录中获得;但不包括在打包中。但是,您需要确保库jar应该在JVM的类路径中的某个位置可用。
https://stackoverflow.com/questions/19024941
复制相似问题