ghostdog74
ghostdog74

Reputation: 342363

Java win32 libraries/api

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

Upvotes: 3

Views: 1734

Answers (5)

MaS
MaS

Reputation: 393

I know it's an older question with an already accepted answer, but since someone might still take a look at it, I'll add my two cents to it, too.

As the others suggested JNA seems like the way to go. Since JNA (and JNA Platform) don't provide a 1:1 mapping of all methods it's also possible to write your own API methods. We did it like described in the question What is the best way to determine the number of GDI objects within a Java program?

Upvotes: 0

Cerber
Cerber

Reputation: 2939

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", "A.so" 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
  Native.register("A");
  //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

Upvotes: 6

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285403

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

Upvotes: 2

Michel Jung
Michel Jung

Reputation: 3276

You may find SIGAR useful

Upvotes: 2

vickirk
vickirk

Reputation: 4067

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

Upvotes: 0

Related Questions