Java API文档中建议的通过运行"schenagen“生成模式的说明适用于JDK7,但不适用于JDK8。
这是文档页面:http://download.java.net/jdk8/docs/technotes/guides/xml/jaxb/index.html
下面是本页中的一行代码,其中包含指向说明的链接:
“运行模式生成器(模式生成器): [command-line instructions](https://jaxb.java.net/2.2.4/docs/schemagen.html), [using the SchemaGen Ant task] ”
架构生成器无法工作,因为某些类已从com.sun.mirror.apt.AnnotationProcessorFactory“中删除:"java.lang.ClassNotFoundException: JDK8
这里还有另一个建议的解决方案:Generating XSD schemas from JAXB types in Maven?
此解决方案也适用于JDK7,但不适用于JDK8;它将以类似的错误结束:
“类未找到not /sun/tools/apt/Main.class”
根本原因可能是相同的:从JDK8中删除了批注处理工具。这个变化很久以前就在JEP 117中计划好了:http://openjdk.java.net/jeps/117
现在,如何使用JDK8从(JAXB)注释的Java类生成XML schema文件?
发布于 2015-09-21 02:28:30
这是"jaxb2-maven-plugin“中的一个bug。您必须使用1.6版或更高版本的插件
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>schemagen</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<includes>
<include>com/projectname/model/*.java</include>
</includes>
<outputDirectory>${project.build.directory}/schemas</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>发布于 2014-03-21 00:47:41
您可以在JAXBContext上使用generateSchema方法来生成XML Schema:
https://stackoverflow.com/questions/22539659
复制相似问题