Solved

Problem Running Java Applet

Posted on 2003-10-31
4
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Html Table Looping (part 2) 5 35
passing enum to a method 4 36
American Express @Work site and Java 4 69
netbeans can not run self signed app 8 14
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

730 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