Hello, I would like to create a node to run a C program. The program reads and writes 3D molecular structures. Is ti possible *without* translating the whole application in Java? Many thanks PS there was a similar post some years ago: http://tech.knime.org/node/20153
Hi,
yes, by using the Java JNI technology. You basically have to:
- Design a Java class with the methods you need (using the native keyword)
- Generate the C-stubs using the command: javah -jni MyClass (See example below)
- Implement the generated stubs to call your native methods.
- Load your native library wrapper
If you native library is a COM object, it’s slightly more involved.
There’s a lot of info on this on the Web, for example:
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
Here’s a simple example:
public final class MyClass implements IMyClass {
private final native String nativeGetProperty();
public final String getGetProperty() {
return nativeGetProperty();
}
static {
System.loadLibrary("theNativeLibrary");
System.loadLibrary("myWrapperAroundNativeLibrary"); // NOTE: No DLL endings; libraries must be in PATH
}
}
Hi,
thanks for the answer. JNI may be overkill. I wrote a wrapper using
ProcessBuilder
It works fine on OS X and Linux.
I’ll see if I can use it in KINME
Let’s put it another way
- MyCApp < input > output
- java CWrap input output
is that enough to write a KNIME node to start the C application ?
Yes it works very well.
ProcessBuilder