Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 496
  • Last Modified:

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
0
Super26
Asked:
Super26
  • 3
1 Solution
 
lwinkenbCommented:
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>

0
 
lwinkenbCommented:
>>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.
0
 
Super26Author Commented:
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";
};


0
 
lwinkenbCommented:
>>Isn't there another simpler way like editing the policy file to include a grant permission statement?
AFAIK you must sign the applet to get it to do what you are trying to do.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now