Java win32 libraries/api

Asked by At

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

4 Answers

Cerber On Best Solutions

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

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

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 !!!

(end of answer)

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

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

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

Just write the following and JNA will do the rest :

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

and use it :

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

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

vickirk On

Afraid not, you would have to write your own jni wrapper for the win32 api calls you need.

Michel Jung On

You may find SIGAR useful

Hovercraft Full Of Eels On

JNA would be easier to use than JNI and only minimally slower. I recommend it strongly: JNA