• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jni / java.lang.UnsatisfiedLinkError occurred at System.loadLibrary

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi~
Sorry for my English.

I created files like below.

TestJNI.java


TestJNI.c


build.sh


then executed "build.sh". but error occurred.

iknow82@notebook :~/tmp/test$ ./build.sh
Exception in thread "main" java.lang.UnsatisfiedLinkError: no TestJNI in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at TestJNI.<clinit>(TestJNI.java:6)

Is there anyone who tell the tips to fix the error?
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the error itself tells you the problem. You need to set java.library.path to point to the directory that contains the shared objects/dlls.

You can do this using the -D option to the java executable.

java -Djava.library.path="path/to/the/directory" ...
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

JNI is far too difficult for us who are just “beginning”(‍), so I shall move this discussion.
 
John Pyun
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've resolved the issue by simple way. just changed .so library name 'TestJNI.so' to 'libTestJNI.so'.
It's Ubuntu 14.04 x64.
thanks for your attention.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That change sounds dangerous. Did you copy the original .so?
 
John Pyun
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd heard several solutions to 'java.lang.UnsatisfiedLinkError' exception.
one is to set LD_LIBRARY_PATH and another is to run app by 'java -Djava.library.path=<<library path>> <<class name>>'.
In my case. although accepted two solutions. couldn't read TestJNI.so file. but after was renamed 'libTestJNI.so'. It works. of course, it was launched 'java -Djava.library.path=<<library path>> <<class name>>'.
I don't know why %modulename%.so format could be read by java.

ps. you know... my english is not good. so if there is my misunderstanding, forgive...
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if another program needs the TestJNI.so link?
 
reply
    Bookmark Topic Watch Topic
  • New Topic