Issue Details (XML | Word | Printable)

Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: ioannism
Votes: 3
Watchers: 3

If you were logged in you would be able to see more operations.

Annotation plugin does not include the project's classpath when annotating generated code

Created: 22/May/12 10:28 PM   Updated: 16/Mar/14 09:54 AM
Component/s: jaxb2-basics
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Tags: annotation xjc classpath
Participants: ioannism, jesseplymale and lexi

 Description  « Hide

Given the following annotation (defined in the same project along with ExistingCustomerValidator class )

package com.tktserver.constraints;

@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })
@Constraint(validatedBy = { ExistingCustomerValidator.class })
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']">
			field="electronicUserId" />

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 Method)
	at java.lang.ClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(
	at org.jvnet.annox.parser.XAnnotationParser.parse(
	... 31 more

Other JSR-303 annotations work fine. I believe that the problem lies in the fact that the xjc plugin does not consider the project's classpath and therefore won't compile for Annotations that have class references in the main project. A workaround is to create a separate maven project and use it as a dependency but this is Ugly.

lexi added a comment - 23/May/12 10:18 AM

Thanks for the report.

ioannism added a comment - 23/May/12 10:20 AM

You're welcome, let me know if you need any more info.

jesseplymale added a comment - 04/Dec/12 09:20 PM

I had a similar issue, but the annotations that I was trying to annotate on the JAXB class were not custom annotations that I had defined, but rather just annotations that were from a library (Jackson) that was not part of the Java API. Turns out that Maven was not using the project dependencies (of which Jackson was a part) in the classpath when running XJC via the maven JAXB plugin. When I added a <dependencies> element underneath the <plugin> for the JAXB maven plugin, and added Jackson <dependency> element to that, it worked.

Definitely seems like a shortcoming of the Maven JAXB plugin, that it does not put the project dependencies on its classpath during code generation.

lexi added a comment - 16/Mar/14 09:37 AM