Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you know of any JNI wrapper toolkits or libraries that wrap common linux OS APIs? [closed]

I'm looking for a library or toolkit (so I don't have to write it) that will allow me to do common things like the following in Linux:

  • Get the uid for a username.
  • Get user / group membership information.
  • Get information about free space on disk drives.
  • Any other potentially useful API calls that are not normally available in Java because they break portability.

Anyone out there have any ideas?

like image 283
Elijah Avatar asked Jan 24 '23 16:01

Elijah


2 Answers

Not a wrapper for any specific library, but the JNA (Java Native Access) "provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java code"

No JNI or native code is required. This functionality is comparable to Windows' Platform/Invoke and Python's ctypes. Access is dynamic at runtime without code generation.

JNA allows you to call directly into native functions using natural Java method invocation. The Java call looks just like it does in native code. Most calls require no special handling or configuration; no boilerplate or generated code is required.

The JNA library uses a small native library stub to dynamically invoke native code. The developer uses a Java interface to describe functions and structures in the target native library. This makes it quite easy to take advantage of native platform features without incurring the high overhead of configuring and building JNI code for multiple platforms.

Using JNA, you should be able to call the Linux API directly (same as you would from C).

like image 187
Thilo Avatar answered Jan 31 '23 10:01

Thilo


POSIX for Java sounds like a good place to start, at least. Remember that most of those things you listed are not "Linux", they are just plain old POSIX.

like image 24
unwind Avatar answered Jan 31 '23 10:01

unwind