简体   繁体   English

如何在 Java 中使用 Linux 共享库?

[英]How can I use Linux shared libraries in Java?

Is there any way to call the functions which are in a so library from my Java code?有什么方法可以从我的 Java 代码中调用so库中的函数吗? Generally, is it possible to use Linux so libraries in Java programs?一般来说,在Java程序中可以使用Linux so库吗?

You cannot use arbitrary .so libraries in your Java code.您不能在 Java 代码中使用任意.so库。 You can use JNI to write a wrapper around native code to access from Java.您可以使用 JNI 围绕本机代码编写包装器以从 Java 访问。

However, be aware that doing so negates many of the advantages of using Java.但是,请注意,这样做会抵消使用 Java 的许多优势。 Your code and deployment system now becomes quite fragile and subject to many types of bugs that cannot happen in Java.您的代码和部署系统现在变得非常脆弱,并且容易受到 Java 中不会发生的许多类型的错误的影响。 I would try quite hard to find a pure-Java solution before resorting to using native code.在诉诸使用本机代码之前,我会非常努力地寻找纯 Java 解决方案。

Another wayto access libraries form java besides JNI is JNA .除了 JNI 之外,另一种从 java 访问库的​​方法是JNA

I find that in many cases it's easier to use then JNI, but that's just my personal opinion.我发现在很多情况下使用 JNI 更容易,但这只是我个人的意见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何找出在Linux上运行Java类所需的共享库? - How can I find out which shared libraries I need to run a Java class on Linux? 我如何在我的 Java 应用程序中使用外部库 - How can i use external libraries in my java application 如何将外部库与原子包和Java脚本一起使用? - How can I use external libraries with the scripts atom package and java? 如何在Java中安装httpclient和其他库,以便可以在Eclipse中使用它们? - How can I install httpclient and other libraries in Java so I can use them in Eclipse? 从Linux上的.jar启动时,Java-JNA和共享库UnsatisfiedLinkError - Java - JNA and shared Libraries, UnsatisfiedLinkError when starting from a .jar on Linux 如何将 androidx 库与 exoplayer 库一起使用? - How can I use androidx libraries with exoplayer libraries? 我如何使用引用的库 - how can i use referenced libraries 我如何使用Jmeter插件(库)在Java Desktop应用程序中创建Http和Https负载测试 - How can i use Jmeter plugin (libraries) to create a Http and Https load test in Java Desktop application 如何使用Spring-Boot在Java项目中使用Clojure库? - How can I use Clojure libraries in a Java project, using Spring-Boot? 我可以使用jython将python库导入Java代码吗? - Can i use jython to import python libraries into java code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM