java - "http://annox.dev.java.net"自定义需要 "-Xannotate"开关

标签 java jaxb xsd hyperjaxb annox

我正在尝试通过 hyperjaxb 运行一个真实的模式。我已经使用 jaxb 反复测试了模式,并且 jaxb 每次都正确地导入了模式。但是,当我尝试让 hyperjaxb 从同一模式生成带 hibernate 注释的 java 类时,出现以下错误:

[ERROR] Error while parsing schema(s).Location [ file:/C:/path/to/src/main/resources/schema.xsd{4,32}].
org.xml.sax.SAXParseException; systemId: file:/C:/path/to/src/main/resources/schema.xsd;  
lineNumber: 4; columnNumber: 32; 
Using "http://annox.dev.java.net" customizations requires the "-Xannotate" switch 
to enable this plug-in.

我用谷歌搜索了这个错误消息并阅读了其他关于它的帖子,但没有找到任何清晰的解决方法。我找到的最接近的是 this article ,它表示 annox 插件 由 -Xannotate 命令行参数激活

我读了this link , 但将以下内容添加到 xsd 文件并没有消除错误,可能是因为 xsd 没有在任何地方使用 jaxb 前缀。

xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.1" 
xmlns:annox="http://annox.dev.java.net" 
jaxb:extensionBindingPrefixes="annox"

我已上传包含所有相关 Material 的 zip 文件以快速重现问题 to this link .它是包含预期架构的项目的 zip 文件。重现问题所需要做的就是将命令行导航到解压缩项目的根目录,然后键入 mvn clean install 以重现错误。

我该如何解决这个错误?


编辑:

我已经尝试将以下内容添加到 pom.xml 中的插件配置中,但到目前为止还没有成功。

<args>
    <arg>-Xannotate</arg>
</args>  

第二次编辑:

我在pom.xml中添加了@lexicore的建议,但是结果是一个空指针异常,你可以阅读by clicking on this link .为了促进其他人更轻松地使用 hyperjaxb,我包含了完整的当前 pom.xml at this link .这个修改后的 pom.xml 和上面的 zip 文件一起足以在几分钟内重现问题。这是配置问题还是错误?

最佳答案

为了新用户的兴趣,我现在将回答这个具体问题。

如果您看到报告的错误:

Using "http://annox.dev.java.net" customizations requires the "-Xannotate"
switch to enable this plug-in.

这意味着,嗯,您必须包含“-Xannotate”开关才能启用此插件。请参阅首页上的文档 jaxb2-annotate-plugin :

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <configuration>
        <extension>true</extension>
        <args>
            <arg>-Xannotate</arg>
        </args>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-basics-annotate</artifactId>
            </plugin>
            <!-- Add the dependencies with your annotations as 'plugins' below -->
            <plugin>
                <groupId>org.jvnet.jaxb2_commons</groupId>
                <artifactId>jaxb2-annotate-plugin-test-annox-annotations</artifactId>
            </plugin>
        </plugins>
    </configuration>
</plugin>

看到 -Xannotate 开关了吗?就是这个。

jaxb2-annotate-plugin 可以以相同的方式与 maven-hyperjaxb3-plugin 一起使用。这是一个 an example来自 Hyperjaxb tests :

        <plugin>
            <groupId>org.jvnet.hyperjaxb3</groupId>
            <artifactId>maven-hyperjaxb3-plugin</artifactId>
            <configuration>
                <postArgs>
                    <arg>-Xannotate</arg>
                </postArgs>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-search</artifactId>
                    <version>3.0.0.GA</version>
                </dependency>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-annotations</artifactId>
                    <version>3.5.6-Final</version>
                </dependency>
            </dependencies>
        </plugin>

(您不需要包含 jaxb2-annotate-plugin,因为它已经被 maven-hyperjaxb3-plugin 自动包含。)

关于java - "http://annox.dev.java.net"自定义需要 "-Xannotate"开关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26430199/

相关文章:

Java 与 MySQL : float type difference

java - Jaxb - 忽略未知属性

无序列和多次出现的 XML 模式

web-services - Delphi:通过wsdl/xsd实现服务器 SOAP

xml - 有什么方法可以更改 xsd :element? 的默认类型

java - Maven 在 jenkins 上使用错误的 JDK 构建

java - 如何使用 Java 程序修改已编译的 .jar 中的类文件中的字符串?

java - Weblogic - 无法找到属性的设置方法

java - 向 JAX-B 生成的元素添加静态属性

java - JAXB 解码具有不同属性的相同元素 (lang)