I am trying to get my application to run with Java 9, but unfortunately one of the plain jar dependencies, when it tries to load a resource using classLoader.getResource(name)
, gets a null instead.
This, of course, works in Java 8.
I declared a dependency on the module in question using the module file, referring to the name of the module by its jar name (awful), and added the jar as-is (no customization for Java 9) using the --module-path
option.
Here is my approximate module file declaration:
module my.mod {
requires ivy; // the file is called ivy-2.4.0.jar
}
And I run with this command:
java --module-path my-mod.jar:ivy-2.4.0.jar -m my.mod
When I run the application, it works fine if the library doesn't try to load that resource... but if it does, it gets a NullPointerException
at the line it tries to use the resource.
I can see the resource is present in the correct path in the jar file.
I've tried running my application both as a jar (shown above) and just with the class files:
java --module-path modules-dir:ivy-2.4.0.jar -m my.module/my.Main
In the latter case, the error is different, but related: Ivy can't even find a properties file it tries to load from its own jar!
Is there any workaround, is this a known bug, or am I doing something wrong?
Java Module System is a major change in Java 9 version. Java added this feature to collect Java packages and code into a single unit called module. In earlier versions of Java, there was no concept of module to create modular Java applications, that why size of application increased and difficult to move around.
java. base is known as the "mother of Java 9 modules." In the following image, you can see the modular aspects of the system and can probably make the leap to understand how a modularized JDK means that you can also modularize your own applications. This is only a few of the 98 platform modules.
xml module, code in modules that read java. desktop becomes dependent on java. xml . Without the requires transitive directive in java.
The classpath is a list of the class libraries that are needed by the JVM and other Java applications to run your program. Similarly, the modulepath is a corresponding list of Java modules needed by your program.
Try to add an 'opens' declaration to the automatic module 'ivy'. That allows access to it's resources:
java --add-opens ivy/<dot.separated.path.to.resources>=ALL-UNNAMED --module-path my-mod.jar:ivy-2.4.0.jar -m my.mod
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With