users@jaxb.java.net

jaxb/annox issue with custom annotations

From: Ioannis Mavroukakis <imavroukakis_at_gmail.com>
Date: Fri, 11 May 2012 01:16:42 +0100

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