views:

327

answers:

4

Hi,

I've been reading Skype4Java (java api for skype) and noticed they use jni to access the skype client.

intuitively I'd assume that there already is a standard library in java that has an OS-sensitive jni implementation to access other processes. I set up to look for one, but couldn't find it.

Is there such a library? if not, is there a best practice to access another process in the os, not necessarily a skype client?

+4  A: 

From Java 1.4 onwards you can use memory mapped files to exchange arbitrary information with another process. See java.nio.MappedByteBuffer for details.

Garth Gilmour
+1  A: 

This is not quite what you're looking for, but will probably help a great deal nonetheless: the Java Native Access project on java.net.

daveb
+1  A: 

Don't forget sockets...

Alexander
+1  A: 

I think that maybe you need to define what 'access' means to you. IF you are talking about plain old inter-process communication, then sockets or JNI are really your best bet.

Garth's comment about using memory mapped files is interesting - I've used MMFs and virtual files for IPC between C applications many times, but it never occurred to me that Java's MMF implementation might be compatible with the native OS virtual file system. These kinds of virtual files usually require non-trivial setup, so I'd be surprised if it would work...

All said, unless you are pumping massive amounts of data between apps, using sockets is probably the most universal and effective way of doing it. Be sure you account for endianness between the host OS and Java VM :-)

Kevin Day