nativelibs4java / BridJ

BridJ: blazing fast Java / C / C++ interop
https://code.google.com/archive/p/bridj/
Other
289 stars 77 forks source link

Critical Java 9 compatibility: Fix wrong path used for looking up resources on class loaders #103

Closed Vampire closed 2 weeks ago

Vampire commented 6 years ago

After BridJ.class.getResource(path) failed various class loaders are tried to get the resource. When used as an automatic module on the module path of a Java 9 application this call will always fail as you can only get resources from your own module with Class#getResource() even if they are opened explicitly. But for getting a resource from the class loader, the path must not start with a slash or will never find anything. Instead the path has to start without a slash and is always evaluated as absolute path. This PR strips the leading slash that is explicitly added before for Class#getResource() where the leading slash is necessary to have the path treated as absolute path.

Vampire commented 6 years ago

As far as I can see the failing builds are a general problem not related to my PR.

Vampire commented 6 years ago

Workaround: make sure bridj.jar is not on the module-path and add it to the classpath instead, then it is not an automatic module but an unnamed module and thus not bound to the restrictions for modules which make the Class#getResource() call work again and the class path code is not necessary.

msgilligan commented 5 years ago

I forked BridJ and created a https://jitpack.io build using the msgilligan-master branch. I have successfully used to build and run webcam-capture on JDK 11/12 in a modular app.

See my comment over in sarxos/webcam-capture for details of the build.gradle I used.

msgilligan commented 5 years ago

Thanks @Vampire !!

Vampire commented 2 weeks ago

As there were various commits over the last years, could this PR please finally be considered? If at some time a new release is made, it would be helpful if this fix is in.

Vampire commented 2 weeks ago

Thanks :-)