question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting JEP native library path for java >10

See original GitHub issue

I am opening a specific issue for this, although it was mentioned #603.

The JEP instance will load itself the native JEP library, but for this to happen we need to add the path to this native library in the java.library.path. So far it was done dynamically, via the user usr_paths field where we appended the JEP native path, and only if some Deep Learning model was required by the config. Unfortunately usr_paths could not be accessed any more as Field via the ClassLoader from Java 11 for security reason.

A possible solution is to use MethodHandler as explained here but it seems not working then for java <9 and stops working again for java 15 because usr_paths cannot be accessed via the ClassLoader any more at all (Caused by: java.lang.NoSuchFieldError: usr_paths).

So adding new paths for native libraries at runtime in Java seems a dead end.

The alternative would be to add the JEP native path when launching the JDK via Gradle, with something like this:

    systemProperty "java.library.path", file("grobid-home/lib/**os-arch***/").absolutePath

If JEP is not used, the library won’t be loaded and this path won’t be used anyway, so it’s not a problem to add the path every time at launch.

For this, we need to identify the right OS info from Gradle (see maybe here for an example), but also normally the version of the JDK and the version of python installed locally…

Note: It does not affect the docker image which will always work fine. In the case of the Docker image, the right JEP is in the system library path because it is fully installed at system-level on the image, and we are not using the embedded native JEP library at all.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kermitt2commented, Jun 1, 2022

Did you try the https://github.com/kermitt2/grobid/issues/688#issuecomment-1140774115 that should extend the list of paths? it does not work?

Sorry, I’ve tried and it works ! I just had to include also the path to grobid-home/lib/lin-64 for other libraries.

systemProperty "java.library.path","${System.getProperty('java.library.path')}:${file("../grobid-home/lib/lin-64/jep").absolutePath}:${file("../grobid-home/lib/lin-64").absolutePath}"

🙌 ✨.

This is great, now we normally only need to make it OS specific and apply it to the run task.

0reactions
kermitt2commented, Jun 1, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Build JEP on Win 10 64 bit · Issue #230 · ninia/jep - GitHub
I got the "Can't find dependent libraries" error because Java could not find python38.dll . I fixed the problem by setting my PATH...
Read more >
How to set the java.library.path in intelliJ Idea - Stack Overflow
1 Answer 1 ... If you run your program from IntelliJ then you can set the java.library.path in the VM options input field...
Read more >
What is java.library.path? How to set in Eclipse IDE? Example
java.library.path is a System property, which is used by Java programming language, mostly JVM, to search native libraries, required by a project.
Read more >
How to Handle the UnsatisfiedLinkError Runtime Error in Java
Check whether the PATH environment variable contains the path to the library. Run the Java program from a terminal with the following command:...
Read more >
A practical look at JEP-412 in JDK17 with libsodium
The very first thing to set up is the native symbol lookup mechanism. In JDK 17 the ... or the code explicitly load...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found