How can I use Linux shared libraries in Java?

空扰寡人 提交于 2019-12-30 05:01:05

问题


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?


回答1:


The answer is "JNI" :)

Here are a couple of links:

  • How to compile dynamic library for a JNI application on linux?

  • http://learn-from-the-guru.blogspot.com/2007/12/java-native-interface-jni-tutorial-hell.html

  • http://docs.oracle.com/javase/6/docs/technotes/guides/jni/




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/13443364/how-can-i-use-linux-shared-libraries-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!