0

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?

lelelo
  • 173
  • 2
  • 12

1 Answers1

0

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):

enter image description here

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.
Oo.oO
  • 12,464
  • 3
  • 23
  • 45
  • What is "nm"? - "nm will will show this symbol inside library" -? – lelelo Oct 02 '17 at 13:13
  • nm is a command in Linux/macOS that shows all symbols inside shared library. I guess, you need to find something that suits your best. E.g.: https://stackoverflow.com/questions/437432/is-there-a-way-to-find-all-the-functions-exposed-by-a-dll – Oo.oO Oct 02 '17 at 13:15