简体   繁体   中英

How does java.* libraries implement the Java native interface to use native methods and it's functionalities?

I wonder how java.* libraries implement the java native interface ?

To be more specific I am investigating the java.awt.Robot and come across native method calls. As I am in windows - does that mean there is a .cpp file laying around somewhere (inside the java.awt.* package?) - that the java.awt.Robot uses?

Whenever you call native code, you have to go via JNI. Typically, you need to build shared library. Calling schema follows (note that you don't call C file - it's just visualization of which method will be called):

在此处输入图片说明

So, in a sense, there is a file that contains source code of the library that you call.

In case of Windows, shared libraries are DLL files in case of Linux they are typically so files and in macOS dylib . If you want to make them "visible" to your Java code, you have few options here. You can put location (directory where library is) in:

  • PATH (windows)
  • LD_LIBRARY_PATH (macOS/Linux)
  • -Djava.library.path - work for all systems, it's just a jvm's argument.

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