问题
I am trying to run a real schema through hyperjaxb. I have tested the schema repeatedly using jaxb, and jaxb imports the schema correctly every time. However, when I try to get hyperjaxb to generate hibernate-annotated java classes from the same schema, I get the following error:
[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.
I have googled this error message and read other postings about it, but have not found any clean instructions for resolving it. The closest I have found is this article, which says that the annox plugin is activated by the -Xannotate command-line argument
.
I read this link, but adding the following to the xsd file did not eliminate the error, probably because the xsd
does not use the jaxb
prefix anywhere.
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.1"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="annox"
I have uploaded a zip file containing all the relevant materials to quickly reproduce the problem to this link. It is a zip file of the project including the intended schema. All you have to do to reproduce the problem is navigate the command line to the root directory of the unzipped project and type mvn clean install
to reproduce the error.
How can I resolve this error?
EDIT:
I have experimented with adding the following to plugin configuration in pom.xml, but so far have not had success.
<args>
<arg>-Xannotate</arg>
</args>
SECOND EDIT:
I added @lexicore 's suggestions to the pom.xml
, but the result is a null pointer exception
, which you can read by clicking on this link. To promote easier use of hyperjaxb
by others, I am including the full current pom.xml
at this link. Together, this revised pom.xml
and the above zip file are enough to recreate the problem in a few minutes. Is this a configuration problem or a bug?
回答1:
You should remove this plugin <artifactId>maven-hyperjaxb3-plugin</artifactId>
<plugin>
<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>maven-hyperjaxb3-plugin</artifactId>
<version>0.6.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<extension>true</extension>
<roundtripTestClassName>RoundtripTest</roundtripTestClassName>
</configuration>
</plugin>
回答2:
I will now answer this specific question for the interest of the new users.
If you see the reported error:
Using "http://annox.dev.java.net" customizations requires the "-Xannotate"
switch to enable this plug-in.
It means, well, that you have to include the "-Xannotate" switch to enable this plugin. Please refer to the documentation on the front page of the 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>
See the -Xannotate
switch? This is it.
jaxb2-annotate-plugin
can be used with maven-hyperjaxb3-plugin
the same way. Here is a an example from 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>
(You don't need to include jaxb2-annotate-plugin
as it is already included by maven-hyperjaxb3-plugin
automatically.)
回答3:
Consider this warning I had to add to Xstian's answer in the previous question:
Warning
This workaround does not use Hyperjaxb at all. This workaround uses the jaxb2-annotate-plugin to add the JPA annotations. This is a task which is normally performed by Hyperjaxb.
That is, if you opt to use this workaround, you completely leave the Hyperjaxb track. Your do not need
jaxb2-annotate-plugin
if you use Hyperjaxb and vice versa, you do not need Hyperjaxb if you add your annotations using thejaxb2-annotate-plugin
.Beware, however, that the
jaxb2-annotate-plugin
only does a very superficial task of adding the annotations which you explicitly configure in your binding files. Hyperjaxb, on the other side is does a very deep and thorough analysis of your schema model and generates reasonable JPA annotations automatically. In certain cases Hyperjaxb even has to augment the generated JAXB code to make it compatible with JPA. These are the features which are out of the scope of thejaxb2-annotate-plugin
.
So if the task is to generate JPA annotations in the schema-derived classes, you use EITHER Hyperjaxb OR jaxb2-annotate-plugin
. It is a completely wrong track to do both in the same time.
I have retagged this specific question to annox
as it is the right tag. Annox is the library behind jaxb2-annotate-plugin and the annox
tag is typically associated with jaxb2-annotate-plugin
-related questions like yours.
来源:https://stackoverflow.com/questions/26430199/http-annox-dev-java-net-customizations-require-the-xannotate-switch