Unable to load library

747 views
Skip to first unread message

Shweta S L

unread,
Aug 12, 2021, 3:30:07 AM8/12/21
to Java Native Access
Hi,

We are using a third party jar java-jq which in turn uses jna to load native library.
We are getting the below exception when the application is run inside a docker container
(Note: this is working fine when run from IDE. The issue is only when run from docker)

[NativeLib] - Copying resource lib/linux-x86_64/libjq.so to: /tmp/1628751828448-0/libjq.so

 [NativeLib] - jq library path: /tmp/1628751828448-0

[Native] - Looking in classpath from sun.misc.Launcher$AppClassLoader@4e0e2f2a for /com/sun/jna/linux-x86-64/libjnidispatch.so

 [Native] - Found library resource at jar:file:/test-service/BOOT-INF/lib/java-jq-1.1.0.jar!/com/sun/jna/linux-x86-64/libjnidispatch.so

[Native] - Extracting library to /root/.cache/JNA/temp/jna4723988906261811700.tmp

[NativeLibrary] - Looking for library 'jq'

[NativeLibrary] - Adding paths from jna.library.path: /test-service/BOOT-INF/lib/java-jq-1.1.0.jar!/lib/linux-x86_64/

 [NativeLibrary] - Trying /tmp/1628751828448-0/libjq.so

 [NativeLibrary] - Loading failed with message: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /tmp/1628751828448-0/libjq.so)

 [NativeLibrary] - Adding system paths: [/usr/lib, /lib]

 [NativeLibrary] - Trying /tmp/1628751828448-0/libjq.so

[NativeLibrary] - Loading failed with message: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /tmp/1628751828448-0/libjq.so)

[NativeLibrary] - Looking for version variants

 [Native] - Looking in classpath from TomcatEmbeddedWebappClassLoader

  context: ROOT

  delegate: true

----------> Parent Classloader:

sun.misc.Launcher$AppClassLoader@4e0e2f2a

 for jq

[NativeLibrary] - Loading failed with message: Native library (linux-x86-64/libjq.so) not found in resource path ([])

[DirectJDKLog] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.UnsatisfiedLinkError: Unable to load library 'jq':

Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /tmp/1628751828448-0/libjq.so)

Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /tmp/1628751828448-0/libjq.so)

Native library (linux-x86-64/libjq.so) not found in resource path ([])] with root cause

java.lang.UnsatisfiedLinkError: Unable to load library 'jq':

Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /tmp/1628751828448-0/libjq.so)

Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /tmp/1628751828448-0/libjq.so)

Native library (linux-x86-64/libjq.so) not found in resource path ([])

at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:302)

at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:455)

at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:397)

at com.arakelian.jq.NativeLib.getNativeLibrary(NativeLib.java:118)


Docker command:

ENTRYPOINT java -cp BOOT-INF/classes:BOOT-INF/lib/* -Djna.debug_load=true -Djna.library.path=/test-service/BOOT-INF/lib/java-jq-1.1.0.jar!/lib/linux-x86_64/ com.test.testApplication

Please advice.

Tres Finocchiaro

unread,
Aug 12, 2021, 10:42:28 AM8/12/21
to jna-...@googlegroups.com
ld-linux-x86-64.so.2: No such file or directory

Your  /tmp/1628751828448-0/libjq.so is being found, but it links against another file called ld-linux-x86-64.so.2 which is not present on your container.

Here's are some very similar issues:

https://github.com/xerial/snappy-java/issues/181

The solution is to ensure the correct version of the above library is present on the system and available in the library search path.

Solutions tend to do one of the following:
  • If this file exists, add the location of ld-linux-x86-64.so.2 to the search path via path manipulation or symlink
    -- OR --
  • Install any packages which may provide ld-linux-x86-64.so.2
    -- OR --
  • Use a container which includes ld-linux-x86-64.so.2 by default
Best regards,

 


--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/6913e581-dce4-4dbe-962c-9f5f4abf9c20n%40googlegroups.com.

Shweta S L

unread,
Aug 13, 2021, 3:38:35 AM8/13/21
to Java Native Access
Thank you for your reply.
This seems to be an issue with alpine. 

Installed packages that provided  ld-linux-x86-64.so.2  and added a link between libjq.so and ld-linux-x86-64.so.2. 

The original issue is resolved but I am encountering another issue

The pod crashed, and below is the error stack 

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)                                                                                         

j  com.sun.jna.Native.invokeInt(Lcom/sun/jna/Function;JI[Ljava/lang/Object;)I+0                                                                        

j  com.sun.jna.Function.invoke([Ljava/lang/Object;Ljava/lang/Class;ZI)Ljava/lang/Object;+211                                                           

j  com.sun.jna.Function.invoke(Ljava/lang/reflect/Method;[Ljava/lang/Class;Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;+271  

j  com.sun.jna.Function.invoke(Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;+37                                               

j  com.sun.jna.Function.invoke(Ljava/lang/Class;[Ljava/lang/Object;)Ljava/lang/Object;+7                                                               

j  com.sun.jna.Function.invokeInt([Ljava/lang/Object;)I+4                                                                                              

j  com.arakelian.jq.JqLibrary.jq_compile_args(Lcom/sun/jna/Pointer;Ljava/lang/String;Lcom/arakelian/jq/JqLibrary$Jv;)Z+20                              

j  com.arakelian.jq.JqRequest.parse(Lcom/sun/jna/Pointer;)Lcom/arakelian/jq/JqResponse;+200                                                            

j  com.arakelian.jq.JqRequest.jq()Lcom/arakelian/jq/JqResponse;+153                                                                                    

j  com.arakelian.jq.JqRequest.execute()Lcom/arakelian/jq/JqResponse;+7  

Appreciate assistance on this. 

Thanks,
Shweta

Matthias Bläsing

unread,
Aug 13, 2021, 12:16:53 PM8/13/21
to jna-...@googlegroups.com
Hi,

please create a minimal project that reproduces your problem. Guessing
from random snippets is difficult and a _minimal_ reproducer also helps
you to focus on the real problem.

But quite frankly: WHY would anyone use a C library to process JSON on
java? There is a shitload of java libraries out there, that do it and
they claim to do it fast (at least some of them). I would only turn to
a native solution, if the Java solution is not viable.

Greetings

Matthias


Am Freitag, dem 13.08.2021 um 00:38 -0700 schrieb 'Shweta S L' via Java
Native Access:
> >  * If this file exists, add the location of ld-linux-x86-64.so.2 to
> > the search path via path manipulation or symlink
> >    -- OR --
> >  * Install any packages which may provide ld-linux-x86-64.so.2
> >    -- OR --
> >  * Use a container which includes ld-linux-x86-64.so.2 by default

Shweta S L

unread,
Aug 17, 2021, 6:02:54 AM8/17/21
to Java Native Access

Hi,
Thank you for your reply.
I changed the code to use a different library and things are working fine now. 

Thanks,
Shweta
Reply all
Reply to author
Forward
0 new messages