Solved

Problem Running Java Applet

Posted on 2003-10-31
4
478 Views
Last Modified: 2010-03-31
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
Comment
Question by:Super26
  • 3
4 Comments
 
LVL 5

Expert Comment

by:lwinkenb
ID: 9662010
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
 
LVL 5

Expert Comment

by:lwinkenb
ID: 9662014
>>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
 

Author Comment

by:Super26
ID: 9707819
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
 
LVL 5

Accepted Solution

by:
lwinkenb earned 20 total points
ID: 9707885
>>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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now