Everything works ok until I got the need to call the doSomething() from
within a java script.
If I invoke doSomething() form javascript the code stops executing
somewhere in the JNI dll.
It just blocks and stops responding at a specific line in the dll.
The applet is signed and the blocking line is handling a camera device
via C++ SDK.
I would appreciate any suggestions.
If it works directly from applet but doesn't work from javascript, after
trying different configurations you may find one where it does work from
javascript. Then it should be possible to find which exact difference in
working and not working configuration cause problems.
Before I only tried with IE and Firefox.
I lowered the restrictions in IE, but the execution still blocks in the dll.
Anyway I tried Opera now and it works with default settings. :-)
Now I have to see what is so different in IE and Firefox..
package com.raditha.articles.jni;
public class NativeHelloWorld
{
public native void displayHelloWorld();
public static void main(String[] args) {
System.load(System.getProperty("user.home") +"/libhello.so");
new NativeHelloWorld().displayHelloWorld();
}
}
Notice the type modifier native? It tells the compiler that we are
calling a function in an external library. We use the load() method to
load the library containing our native code. The official java
tutorial uses the loadLibrary() call. The latter has a few pitfalls.
The first is that libraries on different platforms have different
naming conventions. These are not always obvious to java programmers.
The second issue is that loadLibrary() will only look in predefined
folders for the required library. That rules it it's usage with
applets.