javac --add-modules java.xml.bind for annotation processor?
Eirik Bjørsnøs
eirbjo at gmail.com
Sun Nov 20 22:21:34 UTC 2016
I found that when I use this instead:
javac -J--add-modules -Jjava.xml.bind
then java.xml.bind is made available to my annotation processor and javac
is able to compile.
Two quick questions:
1) Is this by design?
2) How would this work if I made my annotation processor a proper module
which required java.xml.bind? In my initial testing, the processor isn't
picked when if I move it from -classpath to --module-path.
Cheers,
Eirik.
On Sun, Nov 20, 2016 at 10:57 PM, Eirik Bjørsnøs <eirbjo at gmail.com> wrote:
>
> Hi there!
>
> I'm giving Java 9 and Jigsaw a spin on a moderately complex project.
> (Interestingly, the project is itself a module system, so we do stuff like
> annotation processing and dynamic reloading of class loader graphs and
> services)
>
> I'm experienced enough with advanced Java to have shot myself in the foot
> with a java.lang.ClassNotFoundException: java.lang.ClassNotFoundException
> :-) However, I've only recently been looking into Jigsaw in concrete terms.
> So please be kind when I expose my ignorance :-)
>
> Initially, I just want to see if I can get the project to compile on Java
> 9.
>
> So I'm using --add-modules to javac here and there to add modules not
> available to the unnamed module by default. (Not making any proper modules
> yet, that will be the next step).
>
> This seems to be working fine, except for one of our annotation
> processors, which happens to use JAXBContext from java.xml.bind.
>
> I added --add-modules to javac (via Maven configuration), but my
> annotation processor still can't load JAXBContext and fails with this
> message:
>
> $ java -version
> java version "9-ea"
> Java(TM) SE Runtime Environment (build 9-ea+144)
> Java HotSpot(TM) 64-Bit Server VM (build 9-ea+144, mixed mode)
>
> $ mvn clean install -e
>
> This fails with:
>
> Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBContext
> at com.example.processor.ProcessorUsingJavaXmlBind.process(
> ProcessorUsingJavaXmlBind.java:24)
> at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.
> callProcessor(JavacProcessingEnvironment.java:959)
> at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.
> discoverAndRunProcs(JavacProcessingEnvironment.java:875)
> at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.
> access$2100(JavacProcessingEnvironment.java:106)
> at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$
> Round.run(JavacProcessingEnvironment.java:1182)
> at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.
> doProcessing(JavacProcessingEnvironment.java:1290)
> at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(
> JavaCompiler.java:1260)
> at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.
> compile(JavaCompiler.java:939)
> at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl$1.
> call(JavacTaskImpl.java:106)
> at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl$1.
> call(JavacTaskImpl.java:100)
> at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(
> JavacTaskImpl.java:137)
> ... 28 more
>
> I've confirmed that this reproduces using only javac:
>
> $ cd example-module
>
> $ javac -d target/classes -classpath target/classes:$HOME/.m2/
> repository/com/example/annotation-processor/1.0-
> SNAPSHOT/annotation-processor-1.0-SNAPSHOT.jar: -sourcepath
> src/main/java/ -target 1.9 -source 1.9 --add-modules java.xml.bind
> src/main/java/com/example/module/SomeClass.java
>
> java.xml? true
> java.xml.bind? false
>
>
> An annotation processor threw an uncaught exception.
> Consult the following stack trace for details.
> java.lang.NoClassDefFoundError: javax/xml/bind/JAXBContext
> at com.example.processor.ProcessorUsingJavaXmlBind.process(
> ProcessorUsingJavaXmlBind.java:24)
> at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.
> callProcessor(JavacProcessingEnvironment.java:959)
>
>
> I've reduced this to a minimal-ish test case, available on Github:
>
> https://github.com/eirbjo/java-xml-bind-processor
>
> Here's the annotation processor:
>
> https://github.com/eirbjo/java-xml-bind-processor/blob/
> master/annotation-processor/src/main/java/com/example/processor/
> ProcessorUsingJavaXmlBind.java
>
> The class under compilation and the annotation:
>
> https://github.com/eirbjo/java-xml-bind-processor/blob/
> master/example-module/src/main/java/com/example/module/SomeClass.java
> https://github.com/eirbjo/java-xml-bind-processor/blob/
> master/example-module/src/main/java/com/example/module/SomeAnnotation.java
>
>
> Any clues?
>
> Cheers,
> Eirik.
>
>
>
>
More information about the jigsaw-dev
mailing list