
comp.lang.vrml FAQ
Answers
3. Problems with Java
Installing most VRML browsers will automatically install the VRML Java classes. Here are some defaults I know about:
|
Windows 95/Netscape Navigator and Communicator |
|
|---|---|
| Cosmo Player 2.1 | C:\Program Files\Netscape\Navigator\Program\Plugins\Npcosmop21.zip |
| C:\Program Files\Netscape\Communicator\Program\Plugins\Npcosmop21.jar | |
| WorldView 2.0 | C:\Program Files\WorldView for Netscape Navigator\classes |
| Community Place | C:\Program Files\Community Place Browser\lib\java\vsclass.zip |
| CCPro | C:\Program Files\Blaxxun Interactive\CCPro\Java\classes |
|
Unix |
|
| Cosmo Player 1.02 (IRIX) |
/usr/CosmoPlayer/classes/vrml It's sometimes necessary to copy that directory to ~/.netscape/plugins/classes/vrml |
Does someone know the location for the Java classes in other VRML browsers? Other platforms?
First, make sure your VRML browser supports Java in Script nodes. Cosmo Player, Community Place,
and WorldView are among the browsers known to have full Java script support.
There are two classes of VRML browsers on Windows 95 and NT machines: one modifies the autoexec.bat
file to add the VRML classes to your CLASSPATH environment variable. The other takes advantage of
a shortcut in Netscape Navigator and Communicator that lets the plugin look for a .zip or .jar
file in the Netscape plugins folder. The former kind of browser is more susceptible to CLASSPATH problems.
WorldView and Community Place modify autoexec.bat and Cosmo Player uses the plugins folder.
If you've got WorldView or Community Place you'll need to follow a clever procedure devised by Jeff Harrington:
First, try typing in a DOS window this:
set CLASSPATH=c:\java\vrmlOr wherever your Java classes are. Now, from the same DOS window, test it by running Netscape from the DOS prompt:
CD \ CD "Program Files\Netscape\Navigator\Program"and type:
NetscapeIF that works, then you're in business. Add as statement to your
autoexec.batlike the following:set CLASSPATH=c:\java\vrml;%CLASSPATH%IF that doesn't work try another path name. Your problem is certain though:
CLASSPATHis not assigned correctly to tell Netscape where to look for external Java classes.
Not only can you get in trouble from having too few Java classes in your CLASSPATH, you can have
problems when you have too many. The safest thing to do is start from zero (nothing in CLASSPATH),
read the error messages, and add classes until it works.
Let me add to this some advice from Justin Couch: there are some persistent Java problems (e.g., Java Script
nodes work fine, but the EAI won't work) that can only be resolved by uninstalling Netscape and all its plugins,
reinstalling it in a folder with a different name, and reinstalling your VRML plugin.
Still other problems arise when you have multiple VRML browsers that support Java scripting. There's a page at the VRMLworks that discusses multiple plugin problems.
Your Java compiler doesn't know where your VRML classes are. If you're using javac, the command-line compiler
in Sun's Java Development Kit (JDK), you'll need to set your CLASSPATH environment variable. Other
Java compilers or programming environments may have a different way to set a search path, but the following will
apply with some modifications for your system. The situation is further complicated by Sun's JDK 1.0x not always
recognizing classes that are in zip files. And yet further complications arise because some compilers use DEVCLASSPATH
instead of CLASSPATH.
Here's a solution that worked for me for javac on Windows 95:
C:\Java\Classes. Newer versions of WinZip recognize
jar files, but if you have an older version you can simply add jar files to your file
types to be opened with WinZip.
CLASSPATH:
SET CLASSPATH=C:\Java\Classes\;.;%CLASSPATH%
You may need to try DEVCLASSPATH as well.
JAVAC foo.java
On Unix systems do the same thing, except you'll use your shell's normal way to set environment variables:
# set CLASSPATH=/usr/local/java/whatever # export CLASSPATH
% setenv CLASSPATH /usr/local/java/whatever
If that works, and it may take some experimentation to get the CLASSPATH right, add the line you
typed in step 3 above, either to autoexec.bat or to the initialization file or preferences list for
your Java compiler. Don Brutzman has some more information on setting
up to compile and run Java at the Naval Postgraduate School.
First of all, look in your Java console, if your web browser has one. Determine what the Java Virtual Machine (JVM) or Java runtime is telling you isn't there. If the class or object that it can't find really is there, there are two possible explanations:
for(int i = 0; i<SOME_NUMBER; i++)
{
Browser b = Browser.getBrowser();
if(b == null)
sleep(SOME_TIME_VALUE)
else
break;
}
I've seen lots of people use 5 for SOME_NUMBER and 500 for SOME_TIME_VALUE. Others
do it as follows:
for(int i = 0; i<SOME_NUMBER; i++)
{
Browser b = Browser.getBrowser();
if(b != null)
break;
try {
Thread.sleep(SOME_TIME_VALUE);
}
catch(InterruptedException e)
{ // empty action
}
}
Justin notes that you may have to repeat this with getNode(). And I'll add that whenever you're
getting null pointers that seem to tell you that objects aren't there yet, do a spin like either of the examples
above. I've also found that moving the initialization of pointers out of the initialize() method into
the function that's called by the script will work, particularly if the script depends on a user action, at which
point we can safely assume that the world has loaded.
Justin Couch has reported that a different NullPointerException can occur with Netscape Communicator with the
AWT patch installed. This appears to be a bug in Communicator, and the workaround is to remove any reference to
the Netscape classes from the CLASSPATH.
First, make sure it's the EAI that's broken, not your code. The examples in Chris Marrin's EAI draft spec should all work. If some of them work and some of them don't, your browser doesn't support all of the EAI classes correctly. Ross Finlayson's EAI FAQ has a number of hints for getting the EAI working on your machine. And Michael Paulitsch's VRML Examples show a number of Java Script and EAI techniques, though it may be wise to use the spin technique shown in the previous FAQ if you get NullPointerExceptions.
A new symptom has shown up with the release version of Cosmo Player 2.1. The error message is "netscape.javascript.JSException:
unable to reflect embed with index 0 - not loaded yet?" It used to be that you could have the Java classes
for other browsers in your CLASSPATH and Cosmo Player would ignore them. That's no longer so, and
you have to get rid of them. The easiest way is to rename the file or folder. For example, C:\Java\classes\current.zip
is in my CLASSPATH; I rename it to foo.zip. Then when I want to use the other browser,
I rename it back to current.zip.
![]()
Did I leave something out on one of these questions that you need to know? Let me know.
-- Bob Crispen
-- Saturday, March 4, 2000