Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB in Java 9 module issues

I'm upgrading our application to use Java 9 (baby steps... once we get 9 working, we'll jump to 10). One of the issues that we've run into is that at runtime, we're getting a module exception, and I can't seem to figure out what's going on. I'm admittedly new to modules, and have read all I can find about the topic, but I'm guessing this is probably a simple answer.

The runtime to invoke is

java --add-modules java.se,java.se.ee -cp mainjar.jar:jaxb-api.jar:jaxb-impl.jar:jaxb-core.jar foo.bar.Launch

The exception kicking out happens while attempting to read XML Data:

 WARN:09:22:10.777 [main] (Preference:969) - Failed to unmarshal preference value for key [launch.maxMemory]: javax.xml.bind.JAXBException: Package java.lang with JAXB class java.lang.Integer defined in a module java.base must be open to at least java.xml.bind module.
javax.xml.bind.JAXBException: Package java.lang with JAXB class java.lang.Integer defined in a module java.base must be open to at least java.xml.bind module.
    at [email protected]/javax.xml.bind.ModuleUtil.delegateAddOpensToImplModule(Unknown Source)
    at [email protected]/javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at [email protected]/javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at [email protected]/javax.xml.bind.ContextFinder.find(Unknown Source)
    at [email protected]/javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at [email protected]/javax.xml.bind.JAXBContext.newInstance(Unknown Source)
like image 417
Robert K Avatar asked Aug 31 '26 08:08

Robert K


1 Answers

I had a similar problem.
I had my entities in com.redeg and the classes for working with XML in com.redeg.xml and adding a line opens com.redeg.xml to java.xml.bind to the module-info.java file helped.

module-info.java:

module com.redeg {
    exports com.redeg;
    requires java.xml.bind;
    opens com.redeg to java.xml.bind;
    opens com.redeg.xml to java.xml.bind;
}
like image 56
tma Avatar answered Sep 02 '26 22:09

tma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!