bytedeco / javacpp

The missing bridge between Java and native C++
Other
4.46k stars 581 forks source link

java.net.MalformedURLException: Unknown protocol: jar #581

Open jeffgennari opened 2 years ago

jeffgennari commented 2 years ago

I've encountered a problem accessing classes with newer versions of java:

Uncaught Exception: java.lang.UnsatisfiedLinkError: java.net.MalformedURLException: Unknown protocol: jar java.lang.UnsatisfiedLinkError: java.net.MalformedURLException: Unknown protocol: jar at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1759) at org.bytedeco.javacpp.Loader.load(Loader.java:1345) at org.bytedeco.javacpp.Loader.load(Loader.java:1157) at org.bytedeco.javacpp.Loader.load(Loader.java:1133)

The interesting thing is that this only seems to happen with later versions of Java (15+). When I run the same code in Java11, i do not get this error?

saudet commented 2 years ago

That's probably not related to the Java version, but to one of your libraries incorrectly overriding the URL protocol.

jeffgennari commented 2 years ago

I'm not sure, things work fine in Java 11, but not Java 17 with all other libraries unchanged

saudet commented 2 years ago

I've just given JavaCPP a spin with Maven 3.8.4 and JDK 17! While I'm getting a java.lang.reflect.InaccessibleObjectException from the OSGi tests (@timothyjward Is OSGi incompatible with JDK 17?), apart from that, all tests pass normally.

@jeffgennari What happens if you try to build JavaCPP from source with mvn clean install -Djavacpp.platform=linux-x86_64?

timothyjward commented 2 years ago

@timothyjward Is OSGi incompatible with JDK 17?

I’m not aware of anything at a spec level, although some of the Java changes have caused issues for older implementations. It is probably as simple as needing to update the version of the OSGi framework implementation running the tests.

The current dependency is https://github.com/bytedeco/javacpp/blob/8eaa43ab6088626686b7e7fca047cf633ce8eaf8/src/it/osgi/pom.xml#L161

but the latest release is 7.0.5.

If just updating the version doesn’t fix it then it may also be necessary to add some JVM “opens” flags when launching. This will be related to how frameworks have implemented things internally.