[Durham] Calling C code from Java

Richard Mortimer richm at oldelvet.org.uk
Wed Aug 29 22:55:47 UTC 2012


On 29/08/2012 22:31, Martin Ward wrote:
>
> Are there any Java programmers out there that I can ask
> a few questions about calling C functions from Java?
>
I've done a small amount of calling C from Java.

Feel free to ask questions here and I'll see if I know the answer.

The following might help you out in the meantime...


One of the easiest ways to access C from Java is to use JNA
http://en.wikipedia.org/wiki/Java_Native_Access

I must admit its been a while since I played with JNA and I don't know 
how availability differs between Sun (Oracle) Java and OpenJDK. I do 
know that its moved to github these days so it tends to suggest that it 
has escaped somewhat from Oracle these days.


There are a few (open source) examples of JNA usage in Jenkins 
(continuous integration server for those who haven't come across it)
https://github.com/jenkinsci/jenkins/tree/master/core/src/main/java/hudson/util/jna

Specifically bindings to GNU C library methods in
https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/util/jna/GNUCLibrary.java

That should be enough to get you started.

Regards

Richard



More information about the Durham mailing list