java - 您是否知道任何包装通用 linux 操作系统 API 的 JNI 包装器工具包或库?

标签 java linux java-native-interface

<分区>

我正在寻找一个库或工具包(因此我不必编写它),它们可以让我在 Linux 中执行以下常见操作:

  • 获取用户名的 uid。
  • 获取用户/组成员信息。
  • 获取有关磁盘驱动器可用空间的信息。
  • 任何其他可能有用的 API 调用通常在 Java 中不可用,因为它们破坏了可移植性。

有人有什么想法吗?

最佳答案

不是任何特定库的包装器,而是 JNA (Java Native Access) “使 Java 程序可以轻松访问 native 共享库(Windows 上的 DLL),而无需编写 Java 代码以外的任何内容”

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.

使用 JNA,您应该能够直接调用 Linux API(与从 C 调用一样)。

关于java - 您是否知道任何包装通用 linux 操作系统 API 的 JNI 包装器工具包或库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/784855/

相关文章:

java - 无法在 Java 中加载属性文件

linux - 连接文件时奇怪的猫行为

linux - 同一项目的SVN分支之间自动切换

java - JVM 在调用本地方法时必须做什么?

java - "consider using jsig library"是什么意思?

java - Spring 和 Hibernate 的 Bean 验证不起作用

java - 我们如何传递数据?

java - 如何在 Apache MINA sshd 中设置服务器身份验证?

linux - QTweetLib 和 request_token

java - 如何从 native 函数返回 QAndroidJniObject?