Reputation: 13700
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?
Upvotes: 7
Views: 967
Reputation: 521
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
Upvotes: 3