Link to home
Start Free TrialLog in
Avatar of Super26
Super26

asked on

Problem Running Java Applet

I am having a problem running a Java program as an applet. I access an MS Access database from my program. I have two runner classes. One is my Java applet and the other is a regular Java application. My program works fine running from the Java applicaton. But when I try to run it as an applet, it gives me the following error:

java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPackageAccess(Unknown Source) at sun.applet.AppletSecurity.checkPackageAccess(Unknown Source) at sun.applet.AppletClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source)


I have replaced the Java.policy file, giving it the permissions it needs. But somehow that hasn't fixed the problem. I have no idea what else could be wrong. I tried running the applet from Ms-Dos, IBM Visual Age, and an html file, all give me the same problem. But my regular Java application works fine on all of these programs.

I would appreciate it if someone could help me. Thanks.

Shabana
Avatar of lwinkenb
lwinkenb

try signing your applet

first make a jar:

jar cvf myApplet.jar *.class

then create a key for your program:
keytool -genkey -keyalg rsa -alias appletkey
fill out the requested info

Then export the key to a certificate
keytool -export -alias tstkey -file appletkey.crt

now sign your jar
jarsigner myApplet.jar appletkey

now in your html file you need:
<APPLET
      code      = "MainClass.class"
        archive = "myApplet.jar"
      width      = "200"
      height      = "200"
      >
</APPLET>

>>keytool -export -alias tstkey -file appletkey.crt
should have read
keytool -export -alias appletkey -file appletkey.crt

If you want more information on these steps, check here:
http://forum.java.sun.com/thread.jsp?forum=63&thread=174214&message=548253

That's where I got this information from.
Avatar of Super26

ASKER

Isn't there another simpler way like editing the policy file to include a grant permission statement?  Hope someone could help me construct another grant permission statement to make my applet access my MS Access database.  Thanks a lot.  This is what I currently have on my policy file:

grant codeBase "file:${java.home}/lib/ext/*" {
  permission java.security.AllPermission;
};

grant {
  permission java.lang.RuntimePermission "stopThread";
  permission java.net.SocketPermission "localhost:1024-", "listen";
  permission java.util.PropertyPermission "java.version", "read";
  permission java.util.PropertyPermission "java.vendor", "read";
  permission java.util.PropertyPermission "java.vendor.url", "read";
  permission java.util.PropertyPermission "java.class.version", "read";
  permission java.util.PropertyPermission "os.name", "read";
  permission java.util.PropertyPermission "os.version", "read";
  permission java.util.PropertyPermission "os.arch", "read";
  permission java.util.PropertyPermission "file.separator", "read";
  permission java.util.PropertyPermission "path.separator", "read";
  permission java.util.PropertyPermission "line.separator", "read";
  permission java.util.PropertyPermission "java.specification.version", "read";
  permission java.util.PropertyPermission "java.specification.vendor", "read";
  permission java.util.PropertyPermission "java.specification.name", "read";
  permission java.util.PropertyPermission "java.vm.specification.version", "read";
  permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
  permission java.util.PropertyPermission "java.vm.specification.name", "read";
  permission java.util.PropertyPermission "java.vm.version", "read";
  permission java.util.PropertyPermission "java.vm.vendor", "read";
  permission java.util.PropertyPermission "java.vm.name", "read";
  permission java.util.PropertyPermission "platform.notASCII.11compatible", "read";
};

grant {
  permission java.io.FilePermission "<<ALL FILES>>", "write";
};

grant {
  permission java.net.SocketPermission "*:8080", "accept, connect, listen, resolve";
};

grant {
  permission java.net.SocketPermission "*:8189", "accept, connect, listen, resolve";
};

grant {
  permission java.lang.RuntimePermission "modifyThreadGroup";
};


ASKER CERTIFIED SOLUTION
Avatar of lwinkenb
lwinkenb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial