-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getResource changed in Loader.findLibrary #276
Conversation
Thanks! Is there no way to keep the package name though? I'd rather not make changes just for the sake of making changes... |
javacpp-side you can very well extract the package from cls and add it as a prefix to the resource. |
Anyway this is a temporary solution allowing to use javacpp from a modular app. But jlink still won't work. As discussed on gitter i believe the best solution is to turn the jar of libs as a named module that "provides" native libs as a service. |
It looks like we wouldn't need to make them into modules, whatever the path is, as long as it's not a valid package name, for example, containing "-" as with the platform names:
http://mail.openjdk.java.net/pipermail/jpms-spec-experts/2016-September/000392.html Could you test this out? |
Do you mean adding the jar to the classpath instead of the module path ? Anything in the module path cannot access what is in the classpath, so this won't work if an application is launched with module path. In our case the .so are not encapsulated, because their path can contain "-" and because their path does not correspond to a java package in the jar. But also because the jar of libs is currently an automatic module, which "opens" all its resources by default. |
Sounds about right, so the classifier JARs should be fine as they are
without adding anything about modules right? Have you already tested them
with jlink? Everything loads and executes properly?
|
The trick to get these kinds of resources included in images created with |
Thank you master :)
The Jar generated by my PRs ? They are right for running with a modular app, not for jlink since the jar of native libs is still an automatic module.
Just made a test to be sure:
|
What happens if we put a dummy module-info.java that exports nothing, does
it still compile and bring in all resources with invalid package names?
|
A module-info.java like this one works:
Resources are found, provided this module is added to the "requires" of the application.
|
So, it basically works without changing the code in JavaCPP? That's great :)
|
You still need to replace cls.getResource by cls.getClassLoader().getResource for option 2, and adjusting the path if you think it's necessary. And for option 1 of course. |
I thought |
cls.getResource look for the resource in cls module only. |
Ok, so let's call |
Actually, let's fall back on |
What makes you think that ? ClassLoader.getResource doesn't know about the class that were used to get the class loader from. And the class loader is not related to a particular module. |
Because that's what Alan Bateman, the architect of JPMS, said in one of the messages linked above. |
Ok, what he says is that cls.getResource will find the resource in cls Module even if the resource is encapsulated, while ClassLoader.getResource will only find the not encapsulated resources, be them in cls module or elsewhere. |
So, anyway would you be OK with a new method like |
Yes, returning the first matching resource is enough, we don't need an array of url like returned by findResources. |
For backward compatibility we need it anyway. |
You can keep it to be sure, the overhead is probably negligible, but if you keep the same path, there is no reason ClassLoader.getResource doesn't find what cls.getResource does. |
All users don't necessarily do what we do in the presets. Backward
compatibility isn't just for you or me, it's for others as well! So,
actually the call to cls.getResource() should go in Loader.findResources().
Do you agree?
|
What I'm tying to say is that if you replace:
by something like:
I believe that the behavior will be identical in a not-modular context, so no backward compatibility issue. |
It's fine for that case, yes, but it's not the only case. |
I've included that addition among other things in the latest commit. With these changes, the output directory for all the presets gets evaluated to |
Works with my modular opencv branch. |
cls.getResource only look for resources in the module containing cls.
Changed to cls.getClassLoader().getResource which looks everywhere.
This change drops the package prefix in the resource searched for, so in the jar of native libs, the libs must be located in /platform/ instead of /org/bytedeco/javacpp/lib/platform/.
The jar of native libs must be an open module for getResource to succeed.
In my latest PR of javacpp-preset it's an automatic module, so open to all.