简体   繁体   中英

How to load third party libraries (like X11 libs) through code in Java?

Whenever JVM fires up, ie when java command is run; it looks for other libraries in /java/jre/lib folder. These libraries along with the third party libraries like X11 libs, are loaded into the memory by the system's dynamic loader (like dld.so in HP Unix).

So is it possible to load third party libraries from code in java? If yes, what could be the side effects?

What you are looking for is the Java Native Interface ( JNI ). Using external native libraries will make your code less portable. It will make your code less stable since none of the Java language guarantees will hold. There can be security manager implications since you application will need permissions to load the library. In my experience there are many difficulties in writing good JNI code; specifically deallocation and debugging.

SWIG may be of use automatically generate the necessary JNI code.

Native libraries are loaded with System/Runtime.loadLibrary . You will then need some code to make translate between the libraries native calls and JNI (Java Native Interface). Then you will need some Java code with native methods defined for calling into the translation code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM