想要生成Class Student来实现Comparable。
public class Student implements Serializable, Comparable<Students> {
... //bean class...
public int compareTo(Student other) {
.....
return somevalue;
}
}
XSD:
<?xml version="1.0" encoding="UTF-8"?><jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:ci="http://jaxb.dev.java.net/plugin/code-injector"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jxb:version="2.1">
<jxb:bindings>
<jxb:globalBindings>
<jxb:javaType name="org.joda.time.LocalDate" xmlType="xs:date"
parseMethod="Javax.xml.bind.DatatypeConverter.parseDateTime"
printMethod="Javax.xml.bind.DatatypeConverter.parseDateTime" />
<xjc:serializable uid="12343" />
</jxb:globalBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="Student.xsd"
version="1.0" node="/xs:schema">
<jxb:bindings node="//xs:element[@name='Student']/xs:complexType">
<inheritance:implements>java.lang.Comparable<Student></inheritance:implements>
<ci:code>public int compareTo(Student other) {
return somevalue;}</ci:code>
</jxb:bindings>
插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<arguments>-extensions</arguments>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaincludes>
<include>
Student.xsd
</include>
</schemaincludes>
<bindingDirectory>src/main/resources</bindingDirectory>
<bindingincludes>
<include>
Student.xjb
</include>
</bindingincludes>
<packageName>com.test.model.example</packageName>
<outputDirectory>src/main/java </outputDirectory>
</configuration>
</plugin>
错误: 无法处理目录
中的模式文件 Unable to parse input schema(s). Error messages should have been provided. (org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.3:generate:default:generate-sources)org.apache.maven.plugin.MojoExecutionException: Unable to parse input schema(s). Error messages should have been provided. at org.jvnet.mjiip.v_2_2.XJC22Mojo.loadModel(XJC22Mojo.java:55) at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:40)
我错过了什么。任何有待解决的帮助表示赞赏。
答案 0 :(得分:0)
我不知道您在pom.xml
中配置JAXB2基础知识的位置。
此处为guide的maven-jaxb2-plugin。 TL; DR:
<project ...>
...
<build>
<plugins>
...
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<extension>true</extension>
<args>
<arg>-Xinheritance</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>...</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
您正在使用jaxb2-maven-plugin,我找不到在其文档中使用XJC插件的指南,但有this answer