javac --add-modules java.xml.bind for annotation processor?
Eirik Bjørsnøs
eirbjo at gmail.com
Sun Nov 20 23:39:33 UTC 2016
Turns out that:
a) Maven treats -J arguments in a special way which hides them from the
debug log, but they're still passed on to javac
b) Maven parses the javac output for error messages, but drops any output
not following the javac output format.
So using <arg>-J--add-modules=java.xml.bind</arg> does actually work!
But my question remains:
What's the difference between -J--add-modules and --add-modules in javac?
I guess --add-modules specifies modules that javac should allow compilation
against, while -J--add-modules adds modules which should be visible to
javac itself?
Eirik.
On Sun, Nov 20, 2016 at 11:45 PM, Eirik Bjørsnøs <eirbjo at gmail.com> wrote:
>
> Claes,
>
> Btw, the annotation processor has been _compiling_ fine all along.
>
> The problem happens when the example-module is compiled with the
> annotation-processor on the javac -classpath
>
> Eirik.
>
> On Sun, Nov 20, 2016 at 11:23 PM, Claes Redestad <
> claes.redestad at oracle.com> wrote:
>
>> Hi Eirik,
>>
>> compiling com.example.processor.ProcessorUsingJavaXmlBind standalone
>> seems to work fine with --add-modules java.xml.bind - instead it
>> appears as if maven-compiler-plugin doesn't preserve argument order, so
>> you need to use the joined argument form in your pom.xml:
>>
>> <arg>--add-modules=java.xml.bind</arg>
>>
>> I tried this on your minified example, and seems to work. Thanks!
>>
>> /Claes
>>
>>
>> On 2016-11-20 22:57, Eirik Bjørsnøs 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.ClassNotFoundExcepti
>>> on
>>> :-) 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(Proc
>>> essorUsingJavaXmlBind.java:24)
>>> at
>>> jdk.compiler/com.sun.tools.javac.processing.JavacProcessingE
>>> nvironment.callProcessor(JavacProcessingEnvironment.java:959)
>>> at
>>> jdk.compiler/com.sun.tools.javac.processing.JavacProcessingE
>>> nvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:875)
>>> at
>>> jdk.compiler/com.sun.tools.javac.processing.JavacProcessingE
>>> nvironment.access$2100(JavacProcessingEnvironment.java:106)
>>> at
>>> jdk.compiler/com.sun.tools.javac.processing.JavacProcessingE
>>> nvironment$Round.run(JavacProcessingEnvironment.java:1182)
>>> at
>>> jdk.compiler/com.sun.tools.javac.processing.JavacProcessingE
>>> nvironment.doProcessing(JavacProcessingEnvironment.java:1290)
>>> at
>>> jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAn
>>> notations(JavaCompiler.java:1260)
>>> at
>>> jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(J
>>> avaCompiler.java:939)
>>> at
>>> jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl$1.call(Ja
>>> vacTaskImpl.java:106)
>>> at
>>> jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl$1.call(Ja
>>> vacTaskImpl.java:100)
>>> at
>>> jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExc
>>> eptions(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-p
>>> rocessor/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(Proc
>>> essorUsingJavaXmlBind.java:24)
>>> at
>>> jdk.compiler/com.sun.tools.javac.processing.JavacProcessingE
>>> nvironment.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/maste
>>> r/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/maste
>>> r/example-module/src/main/java/com/example/module/SomeClass.java
>>> https://github.com/eirbjo/java-xml-bind-processor/blob/maste
>>> r/example-module/src/main/java/com/example/module/SomeAnnotation.java
>>>
>>>
>>> Any clues?
>>>
>>> Cheers,
>>> Eirik.
>>>
>>>
>
More information about the jigsaw-dev
mailing list