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

Anthony Vanelverdinghe anthony.vanelverdinghe at gmail.com
Tue May 16 17:30:26 UTC 2017


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