7

Is there any way to call the functions which are in a so library from my Java code? Generally, is it possible to use Linux so libraries in Java programs?

Volker Stolz
  • 7,274
  • 1
  • 32
  • 50
moorara
  • 3,897
  • 10
  • 47
  • 60

3 Answers3

8

The answer is "JNI" :)

Here are a couple of links:

Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190
5

You cannot use arbitrary .so libraries in your Java code. You can use JNI to write a wrapper around native code to access from Java.

However, be aware that doing so negates many of the advantages of using Java. Your code and deployment system now becomes quite fragile and subject to many types of bugs that cannot happen in Java. I would try quite hard to find a pure-Java solution before resorting to using native code.

Eamonn O'Brien-Strain
  • 3,352
  • 1
  • 23
  • 33
  • I agree 100%. But there are many cases when you need to access a piece of hardware that requires a native library. I am having a hard time with this. Unfortunately I already spent weeks looking for a solution (native library seems not to be loaded, sick) – Paulo Pedroso Dec 19 '16 at 15:18
4

Another wayto access libraries form java besides JNI is JNA.

I find that in many cases it's easier to use then JNI, but that's just my personal opinion.

mata
  • 67,110
  • 10
  • 163
  • 162