Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I include a java 9 module at runtime?

I have a server kit that I'm trying to test on the java9 JDK (found here, I'm using the 64-bit Linux version), however I'm encountering the following error shortly after startup:

java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:533)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:186)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:476)

The server kit starts without issue when using java8. Somehow I need to tell the runtime system to include the javax.xml.bind module, however I'm new to java9 and don't know how to do this short of recompiling the entire server kit into a module and adding a dependency on the javax.xml.bind module. Is there a way to resolve this error that doesn't require me to recompile the server kit into a module?

like image 749
Zim-Zam O'Pootertoot Avatar asked Mar 20 '17 15:03

Zim-Zam O'Pootertoot


People also ask

How do I run a Java module?

To set up a module, we need to put a special file at the root of our packages named module-info. java. This file is known as the module descriptor and contains all of the data needed to build and use our new module. We start the module declaration with the module keyword, and we follow that with the name of the module.

Where do I put module-info?

To answer your specific questions: Place module declaration ( module-info. java ) into the project's source root directory (e.g. src/main/java ). It must be among the list of files to compile to be turned into a module descriptor ( module-info.

Which of the following method is correct about module system in Java 9?

Q 7 - Which of the following is correct about Module System in Java 9? A - javac, jlink, and java have additional options to specify module paths, which further locate definitions of modules.


1 Answers

Java EE modules are shipped with the JDK but not resolved by default and java.xml.bind is one of them. In such cases they need to be included explicitly with --add-modules.

In your case, launch with --add-modules java.xml.bind.

like image 165
Nicolai Parlog Avatar answered Oct 13 '22 00:10

Nicolai Parlog