I'm trying to call some third-party C code from an Xpage in IBM Domino. I have a button that has an eventHandler whose action creates a Java object and then tries to execute a method, which simply tries to load and run a simple test C function (via JNA) in a DLL. (This is running under Windows 7.) Here is the Java code:
interface CLibrary extends StdCallLibrary {
int hello();
}
public class MyHelloWorld {
public void testImage() {
CLibrary INSTANCE2 = (CLibrary) Native.loadLibrary("helloWorld", CLibrary.class);
INSTANCE2.hello();
And here is the C code:
#include <stdio.h>
int
hello()
{
printf ("Hello World!\n");
}
I've compiled the C code to a dll, and I've imported the .dll as a Resources->Files in Designer. I've also put the jna.jar file in the ext directory on the server. When I try to run all of this, I get a 500 error. There's a lot going on here, so I'm not sure what the problem is. Logfiles don't reveal much. Has anyone done this before? To summarize, I want to be able go from XPage->Java->C. Thanks!
coincidentally I just did this last night with Xpages, JNA and nnotes.dll.
I suspect that your library is not being loaded in the loadLibrary stage.
nnotes.dll is able to be loaded from xpages without any extra setup, presumably because it is on the system path, however in your case you are supplying your own dll, and I am not totally sure that your dll will be found in the Resources - Files section during loadLibrary() stage.
If you haven't read this article by Jesper Kiaer http://nevermind.dk/nevermind/blog.nsf/subject/calling-the-domino-c-api-from-an-xpage-or-a-java-agent Read that article, and then try out his example of NSFDbSpaceUsage, but do it in an XPage. (he does it in a Java agent but just do in an xpage instead). that way you know JNA will be working with XPages ok.
Once that is working, then can I suggest trying out JNA + your custom dll in a regular Java project, without any Notes/Domino involvement, just to verify that it works in isolation?
You can set the property jna.library.path to add the custom location of the dll. If you also set the property jna.debug_load=true you can see in the console which paths that JNA is looking in for your dll, by default it is the system paths and some other convention to do with classpath and platform.
If it can't find it you will get an UnsatisfiedLinkError, so keep playing around with the library path until you can load your dll. Then at least you will know there is nothing wrong with your dll and JNA.
(You may even be able to set those properties dynamically in your xpage if you don't want to do the isolated plain java application test.)
Then last step is to play around with the location of the dll to get it loading in your xpages. Try using jna.library.path, try the standard locations, read up on the loadLibrary method to find out where the default locations are.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With