How to use an annotation processor which depends on java.xml.bind?

Jonathan Gibbons jonathan.gibbons at oracle.com
Tue May 16 17:58:50 UTC 2017


You need to add java.xml.bind into the runtime environment underlying 
javac, instead of the compilation environment containing the classes 
being compiled.

If you are running javac from the command line, use -J-add-module to 
pass the option to the underlying JVM.

If you are running javac via an API in an existing JVM, that JVM has to 
be configured to include the desired module(s).

-- Jon




On 5/16/17 10:30 AM, Anthony Vanelverdinghe wrote:
> Hi
>
> Given an annotation processor, JaxbProcessor, and a simple source 
> file, Test.java, as below.
>
> First I compile JaxbProcessor.java with:
> javac --add-modules java.xml.bind JaxbProcessor.java
> or, by using the JAXB RI:
> javac --upgrade-module-path . JaxbProcessor.java
>
> But I can't find out how to compile Test.java with the JaxbProcessor, 
> i.e. how to replace the dots to make this succeed:
> javac ... -processor JaxbProcessor Test.java
>
> No matter what I try, it gives me: java.lang.NoClassDefFoundError: 
> javax/xml/bind/JAXB
>
> So how can I use an annotation processor which depends on one of the 
> modules that is not resolved by default?
>
> Kind regards, Anthony
>
> == Test.java
>
> @FunctionalInterface
> public interface Test { void test(); }
>
> == JaxbProcessor.java
>
> import java.util.Set;
> import javax.annotation.processing.*;
> import javax.lang.model.SourceVersion;
> import javax.lang.model.element.TypeElement;
> import javax.xml.bind.JAXB;
>
> @SupportedAnnotationTypes("java.lang.FunctionalInterface")
> public class JaxbProcessor extends AbstractProcessor {
>
>     @Override
>     public boolean process(Set<? extends TypeElement> set, 
> RoundEnvironment re) {
>         JAXB.marshal("hello", "world");
>         return true;
>     }
>
>     @Override
>     public SourceVersion getSupportedSourceVersion() {
>         return SourceVersion.latestSupported();
>     }
>
> }
>



More information about the compiler-dev mailing list