?
Solved

Problem Running Java Applet

Posted on 2003-10-31
4
Medium Priority
?
494 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 40 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

752 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