Deployment of natives and jars within applet problem

Hi,

I’m trying to implement an Applet that deploys both the jogl natives and jars onto the users system (like the Madlix viewer).

Natives and jars are copied across to users machine correctly

I put gluegen-rt and jogl.jar into classpath using following code

	URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
	Class sysclass = URLClassLoader.class;
	
	try {
		Class[] parameters = new Class[]{ URL.class };

		Method method = sysclass.getDeclaredMethod( "addURL", parameters );
		method.setAccessible( true );
		method.invoke( sysloader, new Object[]{ u } );
	} 

And then try to load the natives using code hived from the JOGLAppletLauncher.

I get a problem when I call com.sun.opengl.impl.NativeLibLoader.disableLoading();

Stack trace :-

java.lang.ExceptionInInitializerError
at LibInstall.loadNativeLibraries(LibInstall.java:410)
at LibInstall.start(LibInstall.java:53)
at DeployTest.init(DeployTest.java:14)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission sun.jnlp.applet.launcher read)
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.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at com.sun.opengl.impl.NativeLibLoader$4.run(NativeLibLoader.java:158)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.opengl.impl.NativeLibLoader.(NativeLibLoader.java:156)
… 5 more

What could be going wrong?

Thanks

Stu.

Good news. You no longer need to do this or even use the JNLPAppletLauncher any more. The new Java Plug-In at http://jdk6.dev.java.net/6uNea.html now supports launching applets directly from JNLP files, which means you can pull the JOGL extension directly into your applets. I will write documentation on this in the coming days, but here’s a preview. On your web page, use


<applet width="300" height="300" code="MyAppletClassName">
  <param name="jnlp_href" value="my_applet.jnlp">
</applet>

my_applet.jnlp is a JNLP file very similar to for example those used on the jogl-demos page, with an information section, a resources section referring to the JOGL extension JNLP, etc. Instead of using the application-desc tag, use the applet-desc tag:


  <applet-desc
    name="My Applet"
    main-class="MyAppletClassName"
    width="300"
    height="300" />

You can use JVM command-line arguments and system properties (like -Dsun.java2d.noddraw=true, for Windows), heap size specifications, etc. and they will all be honored for your applet.

Give this a try and post if you have any questions. Again, more documentation and examples are coming soon.

Thanks for the advice Ken, I’ll check out the new plugin.

I managed to fix my problem by changing the line

URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();

to

URLClassLoader sysloader = (URLClassLoader)Thread.currentThread().getContextClassLoader();

Jogl.jar wasn’t being loaded by a classloader with the correct security permissions.

Stu.