出现的错误是:java.lang.ExceptionInInitializerError: java.security.AccessControlException: acc ess denied (java.lang.RuntimePermission loadLibrary.helloa) at java.security.AccessControlContext.checkPermission(AccessControlConte xt.java:272) at java.security.AccessController.checkPermission(AccessController.java: 399) at java.lang.SecurityManager.checkPermission(SecurityManager.java:545) at java.lang.SecurityManager.checkLink(SecurityManager.java:837) at java.lang.Runtime.loadLibrary0(Runtime.java:743) at java.lang.System.loadLibrary(System.java:820) at HelloWorlda.<clinit>(HelloWorlda.java:7) at java.lang.Class.newInstance0(Native Method) at java.lang.Class.newInstance(Class.java:237) at sun.applet.AppletPanel.createApplet(AppletPanel.java:586) at sun.applet.AppletPanel.runLoader(AppletPanel.java:515) at sun.applet.AppletPanel.run(AppletPanel.java:293) at java.lang.Thread.run(Thread.java:484)
这是Java端的程序 import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class HelloWorlda extends Applet{ public native void displayHelloWorld(); static { System.loadLibrary("helloa"); } public static void main(String[] args){
In my experience running a native library, you must explicitly extract the file from the jar archive. Try using getResourceAsStream() to get an InputStream for the target library file. Then write it out using FileOutputStream. This appears to make it available locally where the applet is running.Don`t forget you`ll likely have to deal with security issues in order to write a file locally or execute a native library.
ess denied (java.lang.RuntimePermission loadLibrary.helloa)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:272)
at java.security.AccessController.checkPermission(AccessController.java:
399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkLink(SecurityManager.java:837)
at java.lang.Runtime.loadLibrary0(Runtime.java:743)
at java.lang.System.loadLibrary(System.java:820)
at HelloWorlda.<clinit>(HelloWorlda.java:7)
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:237)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:586)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:515)
at sun.applet.AppletPanel.run(AppletPanel.java:293)
at java.lang.Thread.run(Thread.java:484)
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class HelloWorlda extends Applet{
public native void displayHelloWorld();
static {
System.loadLibrary("helloa");
}
public static void main(String[] args){
Frame frame=new Frame("Application");
HelloWorlda app=new HelloWorlda(); frame.add("Center",app);
frame.setSize(200,200);
frame.validate();
frame.setVisible(true);
frame.addWindowListener(new WindowControl(app));
app.init();
app.start();
}
public void paint(Graphics g){ g.drawString("Hello World,both!",25,25); }
public void destroy(){
System.exit(0);
}
}
class WindowControl extends WindowAdapter{
Applet c; public WindowControl(Applet c){ this.c=c;
} public void windowClosing(WindowEvent e){
c.destroy();
}
}
这是C端的程序:
#include<jni.h>
#include"HelloWorlda.h"
#include<stdio.h>JNIEXPORT void JNICALL
Java_HelloWorlda_displayHelloWorld(JNIEnv *env,jobject obj)
{
printf("Applet!\n");
return;
}
file from the jar archive.
Try using getResourceAsStream() to get an InputStream for the target library
file. Then write it out using FileOutputStream. This appears to make it
available locally where the applet is running.Don`t forget you`ll likely have to deal with security issues in order to
write a file locally or execute a native library.
我用了getResourceAsStream(),编译时就通不过。