Hey guys,
Well first of all, please let me say how nice this website is - I'm very pleased to have found it and plan to be sticking around while I'm learning Java as part of my Uni course.
I think I will probably get off to pretty bad start here, by asking a question that is almost certainly a 'Frequently Asked Question'. In my defence, I have looked at quite a few sites on the net and not found the answer.
First, I'll set the scenario...
I'm running java on Linux. My $CLASSPATH variable is set correctly to "/home/jpw48/public_html/java/classes". I have made myself a package which we'll call myPackage. This contains the class Jack.class , so the full location of Jack.class is "/home/jpw48/public_html/java/classes/myPackage/Jack.class". Now, I have 'local' directory, which contains the file Jill.class at "/home/jpw48/java/jill/Jill.class". Jill imports Jack using the statement "import myPackage.Jack;".
Still with me?
Now, Jill extends JApplet, so to run Jill, I have to make Jill.html, which includes the line:
<APPLET code="Jill.class" width="1000" height="800">
I use the command "appletviewer Jill.html" to run Jill, but it doesn't work, complaining of a NoClassDefFoundError at runtime. Clearly, it doesn't know where to find Jack. After some trawling through the internet, I found a way to solve this problem by giving the command:
appletviewer -J-classpath -J$CLASSPATH Jill.html
And this works fine. So what's the problem? The problem is if I try to open Jill.html with my normal browser like this...
firefox Jill.html &
... it doesn't work for the same reason as why appletviewer didn't work initially - it doesn't know the classpath. There's no command line parameter I can give to firefox to tell it the classpath; it's got to be put into the html file somehow, I reckon.
How?
Thanks guys, I look forward to hearing your response(s).
Kind regards,
John