jaxb2-commons
  1. jaxb2-commons
  2. JAXB2_COMMONS-32

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

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: jaxb2-basics
    • Labels:
      None

      Description

      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 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.

        Activity

        Hide
        lexi added a comment -

        Thanks for the report.

        Show
        lexi added a comment - Thanks for the report.
        Hide
        ioannism added a comment -

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

        Show
        ioannism added a comment - You're welcome, let me know if you need any more info.
        Hide
        jesseplymale added a comment -

        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.

        Show
        jesseplymale added a comment - 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.
        Hide
        lexi added a comment -
        Show
        lexi added a comment - http://jira.highsource.org/browse/JIIB-55

          People

          • Assignee:
            Unassigned
            Reporter:
            ioannism
          • Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: