G
George Anadiotis
Hello all
This one has been posted at Sun's site forums as well, but since i got
no reply from there i thought i'd try my luck here as well. So here
goes:
I am trying to develop an applet whose funtionality includes loading a
..dll library and invoking some function implemented as native code.
The dll implementation is actually third-party, but i am pretty
confident there's nothing wrong with it because it works fine when
invoked in a standalone application.
Before going any further, i should note that i am aware of security
restrictions, signing applets etc - i have temporarily bypassed that
limitation during development by granting a
java.security.AllPermission permission in my JRE policy file.
In fact, the dll itself even works fine when invoked from the applet
source directory - i.e. directory source contains the applet class
file and the dll file, so when opening the applet using appletviewer
and a test html page that contains something like this: <APPLET
CODE='PrintApplet.class' WIDTH=426 HEIGHT=322>, everything works fine.
Trouble starts when i try to package the applet source and the dll
into a jar file and open it again using the same procedure, only this
time using something like this in my html:
<APPLET CODEBASE="C:/testdir/PrintApplet" archive="PrintApplet.jar"
CODE="PrintApplet" WIDTH=426 HEIGHT=322>
In this scenario, the dll is loaded using:
InputStream in = this.getClass().getResourceAsStream("ShellExec.dll");
and then saved on the client disk using a FileOutputStream.
What happens then is that i get the following stacktrace:
java.lang.UnsatisfiedLinkError: C:\testdir\PrintApplet\ShellExec.dll:
Invalid access to memory location
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1473)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1368)
at java.lang.Runtime.load0(Runtime.java:737)
at java.lang.System.load(System.java:809)
at ShellExec.<clinit>(ShellExec.java:19)
at PrintApplet.testPrint(PrintApplet.java:200)
at PrintApplet.clearButton_ActionPerformed(PrintApplet.java:215)
at PrintApplet$SymAction.actionPerformed(PrintApplet.java:159)
at java.awt.Button.processActionEvent(Button.java:381)
at java.awt.Button.processEvent(Button.java:350)
at java.awt.Component.dispatchEventImpl(Component.java:3639)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
This seems to suggest that the dll is actually loaded, but then
something gives. Any ideas as to what may be the issue here?
Thanks in advance,
George Anadiotis
This one has been posted at Sun's site forums as well, but since i got
no reply from there i thought i'd try my luck here as well. So here
goes:
I am trying to develop an applet whose funtionality includes loading a
..dll library and invoking some function implemented as native code.
The dll implementation is actually third-party, but i am pretty
confident there's nothing wrong with it because it works fine when
invoked in a standalone application.
Before going any further, i should note that i am aware of security
restrictions, signing applets etc - i have temporarily bypassed that
limitation during development by granting a
java.security.AllPermission permission in my JRE policy file.
In fact, the dll itself even works fine when invoked from the applet
source directory - i.e. directory source contains the applet class
file and the dll file, so when opening the applet using appletviewer
and a test html page that contains something like this: <APPLET
CODE='PrintApplet.class' WIDTH=426 HEIGHT=322>, everything works fine.
Trouble starts when i try to package the applet source and the dll
into a jar file and open it again using the same procedure, only this
time using something like this in my html:
<APPLET CODEBASE="C:/testdir/PrintApplet" archive="PrintApplet.jar"
CODE="PrintApplet" WIDTH=426 HEIGHT=322>
In this scenario, the dll is loaded using:
InputStream in = this.getClass().getResourceAsStream("ShellExec.dll");
and then saved on the client disk using a FileOutputStream.
What happens then is that i get the following stacktrace:
java.lang.UnsatisfiedLinkError: C:\testdir\PrintApplet\ShellExec.dll:
Invalid access to memory location
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1473)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1368)
at java.lang.Runtime.load0(Runtime.java:737)
at java.lang.System.load(System.java:809)
at ShellExec.<clinit>(ShellExec.java:19)
at PrintApplet.testPrint(PrintApplet.java:200)
at PrintApplet.clearButton_ActionPerformed(PrintApplet.java:215)
at PrintApplet$SymAction.actionPerformed(PrintApplet.java:159)
at java.awt.Button.processActionEvent(Button.java:381)
at java.awt.Button.processEvent(Button.java:350)
at java.awt.Component.dispatchEventImpl(Component.java:3639)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
This seems to suggest that the dll is actually loaded, but then
something gives. Any ideas as to what may be the issue here?
Thanks in advance,
George Anadiotis