Determining if Java3D is installed from Applet?

Is this possible to do? Over the last few days I’ve been trying to write an applet that will report the version of Java3D installed on the client’s machine. If Java3D is installed, everything works fine.

But I’m unable to gracefully handle the case where Java3D is not installed. I’ve tried catching a ClassNotFoundException around creating a VirtualUniverse, but that doesn’t work because I throw a ClassDefNotFound before I even enter my init() code.

I’ve tried dymanically loading the class, but that doesn’t work due to the sandbox.
:-/

trying dumping out the system properties, you might find there is a system property setup to describe the j3d install.

Maybe first check if class VirtualUniverse is available. If so, ask VirtualUniverse.getProperties().

This will tell you all about version etc…

Later on, you can get more details from a Canvas3D.


            Map vuMap = VirtualUniverse.getProperties();
        
            Log.logger.fine("version = " +
                           vuMap.get("j3d.version"));
            Log.logger.fine("vendor = " +
                           vuMap.get("j3d.vendor"));
            Log.logger.fine("specification.version = " +
                           vuMap.get("j3d.specification.version"));
            Log.logger.fine("specification.vendor = " +
                           vuMap.get("j3d.specification.vendor"));
            Log.logger.fine("renderer = " +
                           vuMap.get("j3d.renderer") + "\n");

Unfortunately, that doesn’t work. That code fragment is exactly what I was trying to do. But it throws this exception:

java.lang.NoClassDefFoundError: javax/media/j3d/GraphicsConfigTemplate3D
      at java.lang.Class.getDeclaredConstructors0(Native Method)
      at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
      at java.lang.Class.getConstructor0(Class.java:1762)
      at java.lang.Class.newInstance0(Class.java:276)
      at java.lang.Class.newInstance(Class.java:259)
      at sun.applet.AppletPanel.createApplet(AppletPanel.java:566)
      at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1775)
      at sun.applet.AppletPanel.runLoader(AppletPanel.java:495)
      at sun.applet.AppletPanel.run(AppletPanel.java:292)
      at java.lang.Thread.run(Thread.java:536)

As you can see from the stacktrace, there’s no point in there when I’m actually in my applet. This is all the applet loading framework. It’s trying to ensure all the classes are there before it starts the applet.

Another way I tried was to do this:


try {
  Class.forName("javax.media.j3d.VirtualUniverse");
}
catch (ClassNotFoundException e) {
  myApplet.textArea.append("Java3D does not appear to be installed!" + newline);
}

This won’t work because of the sandbox. I get an AccessControlException.

Finally, there are only a few system properties that can be read by the applet. Again, this is due to security. Sun talks about this at http://java.sun.com/docs/books/tutorial/applet/practical/properties.html where there’s a niftly applet that show’s what you can get.

I may have to resort to several applets that load each extension I want to test for and say “Did that work?” on each one of them. It’s very cheesy and not as nice as a single applet that would give a single report.

Ouch, I wasn’t aware an applet can’t do that. So my method doesn’t seem to be appropriate.

Try this one:

this.getClass().getClassLoader().loadClass(“javax.media.j3d.VirtualUniverse”)

No, that’s also invoking the ClassLoader. Applets are forbidden to do that.

This page just suggests you go to a test applet first: http://jdraw3d.herinean.com/ perhaps you’ll have to do similar?

[quote]No, that’s also invoking the ClassLoader. Applets are forbidden to do that.
[/quote]
AFAIK Class.forName(“javax.media.j3d.VirtualUniverse”) should work in an applet… at least it did… 8)