Hello Ioannis,
Please make sure, that your annotation class and its dependencies are available in the classpath of the maven-jaxb-plugin like this:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
...
<configuration>
...
<plugins>
<plugin>
YOUR ARTIFACT HERE
</plugin>
</plugins>
</configuration>
</plugin>
Regrettably, the maven JAXB plugin does not check for the existing classpath of the project. Other plugins are able to do that, so I guess it should be possible and in my opinion this is a bug. I came across the same problem like you.
Hope this helps.
Best regards,
Marko
From: Ioannis Mavroukakis [mailto:imavroukakis_at_gmail.com]
Sent: Friday, May 11, 2012 2:17 AM
To: users_at_jaxb.java.net
Subject: jaxb/annox issue with custom annotations
Hi everyone,
I'm a little stuck with an annotations usage scenario and I was hoping for your input.
Given the following annotation (defined in the same project along with ExistingCustomerValidator class )
package com.tktserver.constraints;
@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = { ExistingCustomerValidator.class })
@Documented
public @interface ExistingCustomerMatch {
String message() default "{customer.notfound}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
/**
* @return The field
*/
String field();
}
and the following jxb customisation
<jaxb:bindings node="xsd:complexType[@name='customer']">
<annox:annotate>
<annox:annotate
annox:class="com.tktserver.constraints.ExistingCustomerMatch"
field="electronicUserId" />
</annox:annotate>
</jaxb:bindings>
I get this when I generate my sources ( it's a Maven project)
Caused by: org.jvnet.annox.annotation.AnnotationClassNotFoundException: Annotation class [com.tktserver.constraints.ExistingCustomerMatch] could not be found.
... 32 more
Caused by: java.lang.ClassNotFoundException: com.tktserver.constraints.ExistingCustomerMatch
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.jvnet.annox.parser.XAnnotationParser.parse(XAnnotationParser.java:76)
... 31 more
Other JSR-303 annotations seem to work fine. What I'm wondering is whether I'm getting trapped by a cyclic dependency here i.e. generate-sources runs first, then compile, therefore there's no ExistingCustomerMatch class available when generate-sources runs..
Thanks,
Ioannis
-------------------------------------------------------
Fachinformationszentrum Karlsruhe, Gesellschaft für wissenschaftlich-technische Information mbH.
Sitz der Gesellschaft: Eggenstein-Leopoldshafen, Amtsgericht Mannheim HRB 101892.
Geschäftsführerin: Sabine Brünger-Weilandt.
Vorsitzender des Aufsichtsrats: MinDirig Dr. Thomas Greiner.