Java win32库/ api [英] Java win32 libraries/api

查看:166
本文介绍了Java win32库/ api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
是否有一个合适的Java win32库,例如,显示当前进程,找出进程已经采用的端口号等等? (或类似WMI库?)
谢谢

hi is there a proper Java win32 library, for example, displaying current processes, finding out port numbers a process has taken etc etc. ? (or something like a WMI library ?) thanks

推荐答案

看看 JNA 。这是一种100%纯java方式与本机代码进行通信。

Have a look at JNA. It's a 100% pure java way to communicate with native code.

他们有一个名为 Platform.jar 包含一些最常见的原生API。

They have a secondary lib named Platform.jar which packages some of the most common native API.

虽然我知道它是什么,但我没有使用平台,所以我不能指出你在哪里可以找到你想要的东西。但是根据我的全球JNA经验,这应该有助于很多!!!

Althought I know what it is, I haven't used platform so I can't point out where you'll find what you're looking for. But from my global JNA experience this should help A LOT !!!

(答案结束)

对于那些想知道它是如何工作的人(在主页上有解释)......好吧,让我们说他们已经为你处理了本地部分,这样你就可以专注于java端。
主要的librairy(jna.jar)捆绑了许多本机库(.dll,.so,.dylib)用于主要的os /架构和java端来操作它们(这解释了jar的大小:~1 Mo)。

For those who wonder how it works (it's explained on their homepage) ... well let's say they've handle the native part for you so that you can focus on the java end. The main librairy (jna.jar) bundles many native libs (.dll, .so, .dylib) for the major os / architectures and the java end to manipulate them (which explains the size of the jar : ~ 1 Mo).

如果要使用多OS名称库A.dll,A.so或libA.dylib,其中包含以下内容:

when you want to use a multi OS lib name "A.dll", "A.so" or "libA.dylib" which contains the following :

int doSomething(char* aString ,byte* aByteArray, long* arraySize)

只需写下以下内容,JNA将完成剩下的工作:

Just write the following and JNA will do the rest :

public class LibAWrapper{
  //tell JNA to link with native library
  Native.register("A");
  //Type mapping in java 
  public native int doSomething(String aString ,byte[] aByteArray, NativeLongByReference arraySize)
}

并使用它:

new LibAWrapper().doSomething("Hello World",....

这意味着如果Platform.jar不适合您的需求应该很容易为你想要的本机库写一个包装器

Which means that if Platform.jar does not suit your needs it should be easy for you to write a wrapper around the native lib that you want

这篇关于Java win32库/ api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆