是否有用于访问本机 Windows API 的 Java 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/606820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a Java library to access the native Windows API?
提问by flybywire
Is there a Java library to access the native Windows API? Either with COM or JNI.
是否有用于访问本机 Windows API 的 Java 库?使用 COM 或 JNI。
采纳答案by GEOCHET
You could try these two, I have seen success with both.
你可以试试这两个,我已经看到两者都成功了。
http://jawinproject.sourceforge.net
http://jawinproject.sourceforge.net
The Java/Win32 integration project (Jawin) is a free, open source architecture for interoperation between Java and components exposed through Microsoft's Component Object Model (COM) or through Win32 Dynamic Link Libraries (DLLs).
Java/Win32 集成项目 (Jawin) 是一个免费的开源架构,用于 Java 和通过 Microsoft 的组件对象模型 (COM) 或通过 Win32 动态链接库 (DLL) 公开的组件之间的互操作。
JNA 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.
JNA 为 Java 程序提供了对本地共享库(Windows 上的 DLL)的轻松访问,而无需编写除 Java 代码之外的任何内容——不需要 JNI 或本机代码。此功能可与 Windows 的 Platform/Invoke 和 Python 的 ctypes 相媲美。访问在运行时是动态的,无需生成代码。
JNA 允许您使用自然的 Java 方法调用直接调用本机函数。Java 调用看起来就像在本机代码中一样。大多数调用不需要特殊处理或配置;不需要样板或生成的代码。
Also read up here:
也在这里阅读:
http://en.wikipedia.org/wiki/Java_Native_Interface
http://en.wikipedia.org/wiki/Java_Native_Interface
The Java Native Interface (JNI) is a programming framework that allows Java code running in a Java Virtual Machine (JVM) to call and to be called1by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages, such as C, C++ and assembly.
Java 本机接口 (JNI) 是一种编程框架,它允许在 Java 虚拟机 (JVM) 中运行的 Java 代码调用和被本机应用程序(特定于硬件和操作系统平台的程序)和用其他语言编写的库调用1语言,例如 C、C++ 和汇编。
http://en.wikipedia.org/wiki/Java_Native_Access
http://en.wikipedia.org/wiki/Java_Native_Access
Java Native Access provides Java programs easy access to native shared libraries without using the Java Native Interface. JNA's design aims to provide native access in a natural way with a minimum of effort. No boilerplate or generated glue code is required.
Java Native Access 使 Java 程序可以轻松访问本机共享库,而无需使用 Java 本机接口。JNA 的设计旨在以最少的努力以自然的方式提供本地访问。不需要样板或生成的胶水代码。
回答by Jason S
回答by Kevin Day
回答by OscarRyz
JNIWrapperor ConfyJfrom from TeamDev.
JNIWrapper或ConfyJ从TeamDev。
回答by Peter Smith
One more option is WinRun4J. It has a native binding layer that aims to be compatible with pinvoke.net(the native binding format used in dot net). See examplesfor more information. Its a little early days so YMMV.
另一种选择是WinRun4J。它有一个本地绑定层,旨在与pinvoke.net(dot net 中使用的本地绑定格式)兼容。有关更多信息,请参见示例。它有点早,所以YMMV。
(full disclosure: i work on the project).
(完全披露:我从事该项目)。
Yet another option is JFFI- this is used in jruby and jython to interact with native libraries.
另一个选择是JFFI- 它在 jruby 和 jython 中用于与本机库交互。