java.lang.ClassNotFoundExceptionthrown oncom.ms.securitypackage when applet runs
SymptomsWhen running an applet in a browser using the Sun JRE, a
ClassNotFoundExceptionis thrown by theClassLoaderon thecom.ms.securitypackage. The same applet runs under the Microsoft VM.Cause
The Microsoft VM provides the proprietary
com.ms.securitypackage for applets and applications to access the security policy at runtime. This package is not available in the Sun JRE, so aClassNotFoundExceptionis thrown when the applet runs.Resolution
The workaround is to migrate the applet source from using the
com.ms.securitypackage to using similar classes in thejava.securitypackage.
For example, the following applet usescom.ms.security.PolicyEngineto assert the network I/O permission before connecting to a URL.
public class AssertPermissionApplet extends java.applet.Applet
{
public void init()
{
try
{
// Assert permission on network I/O
com.ms.security.PolicyEngine.assertPermission
(com.ms.security.PermissionID.NETIO);
java.net.URL url = new java.net.URL(
"http://randomhost/randomfile");
.....
} catch (java.net.MalformedURLException mue) {
}
catch (java.io.IOException ioe) {
}
} // init
}In the Java 2 platform,
java.security.AccessControllerprovides similar functionality for permission assertion. Here is the source code after migration:
public class AssertPermissionApplet extends java.applet.Applet
{
public void init()
{
try
{
// Assert permission on network I/O
java.net.AccessController.checkPermission(new java.net.SocketPermission("randomhost:80", "connect, accept"));
java.net.URL url = new java.net.URL(
"http://randomhost/randomfile");
.....
} catch (java.net.MalformedURLException mue) {
}
catch (java.io.IOException ioe) {
}
} // init
}Please refer to the J2SE API documentation for more details on security.
Related Information
See Security.