This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hello, I'm new and am having problems running an applet, using appletviewer, that uses a class that uses the AS400JDBCDriver class to access data on a AS/400 machine and display the output in a JTable. If I run this java program as a JFrame instead of a JApplet it runs just fine. Is there some sort of applet security issue preventing this applet from finding the AS400JDBCDriver? If so, how can it be resolved? My system CLASSPATH is set to: .;%JAVA_HOME%\lib;%JAVA_HOME%\jtopen_4_1\lib\jt400.jar;C:\j2sdkee1.3.1\lib ****Where JAVA_HOME = c:\j2sdk1.4.2_02****** This applet will run in my WebSphere Development Studio Client for iSeries V.5.0 environment just fine when I run it as a Java Bean / Applet (I'm assuming that WebSphere has a built in appletviewer). My WebSphere Studio environment uses my system class path for its JRE references. So I am using version 1.4.2_02 references everywhere. If I browse out to the source code's directory, from the command line and attempt to compile and view this applet using appletviewer, the applet will compile just fine but give me the following error message when the appletviewer command is run. The two classes used here aree AS400QueryApplet.class and ResultSetTableModel.class. They are both in the same directory with the AS400QueryApplet.html file. C:\Temp\JavaTestStuff>appletviewer AS400QueryApplet.html java.lang.NoClassDefFoundError: com/ibm/as400/access/AS400JDBCDriver at ResultSetTableModel.<init>(ResultSetTableModel.java:35) at AS400QueryApplet.init(AS400QueryApplet.java:35) at sun.applet.AppletPanel.run(AppletPanel.java:353) at java.lang.Thread.run(Thread.java:534) What am I doing wrong? The source will compile but not run. I'm stumped. Please help if you can. Thank you, Chad Schmidt ctschmidt
You need to put the AS400JDBCDriver.class file in a subdirectory named com/ibm/as400/access. Java files are arranged by package (i.e. com.ibm.as400.access) and the class loader looks for a package by looking up the corresponding directory structure. Be advised that an applet can only connect back to the server that it was downloaded from unless it is signed with a digital signature. If your database is on another computer this will be your next problem.
I'm not sure I understand your solution. If I run this program as a JFrame it will connect just fine. Why would I have to copy the AS400JDBCDriver.class from the jt400.jar? Shouldn't it be made available to all java programs from my classpath setting? My database does indeed sit on another machine. I am working from a Windows 2000 Professional workstation and connecting to a AS/400 host in my java program. I looked at the digital signature stuff a little. I looks like that is the next big thing to learn. I guess this is a security issue, correct? I attempted to give the applet access to all resources on my PC by writing a policy and using this policy when running the applet in appletviewer. This was not a successful venture. I actually have the applet security turtorial, as offered by Sun, open on my PC. I will work through that and get a good grasp on this topic and see if it helps solve my problem. Any further suggestions??? Thanks much!
Hi Chad Please make sure that jt400.jar is available to the "applet". Meaning, if its in the system's CLASSPATH it won't work. It has to be visible to the applet. Meaning, you should probably use ARCHIVE attribute of APPLET tag to specify this jar file name so the applet class loader can load the JDBC Driver from the jt400.jar. Also, please post your applet HTML here if possible which might give us more idea if you are not able to solve the problem using ARCHIVE attribute... Regards Maulin
Joined: Nov 04, 2003
Hello Maulin, I read someone's reply, to a similar question like mine, on another message board that hinted on what you are talking about. That makes sense to me but I have never used that attribute of the APPLET tag before. Of course this is my first attempt at writing an applet that actualy does something useful. Here is my current HTML code: <html> <applet code = "AS400QueryApplet.class" width = "400" height = "300"> </applet> </html> As you can see, it is simple and obviously not what I need. If you could point me in the right direction, that would be great. Will I still need to create a system resource access policy? I will look into the usage of the ARCHIVE attribute of the APPLET tag while waiting for a reply. Thanks much!
Originally posted by Chad Schmidt: I'm not sure I understand your solution. If I run this program as a JFrame it will connect just fine. Why would I have to copy the AS400JDBCDriver.class from the jt400.jar? Shouldn't it be made available to all java programs from my classpath setting?
Applets and applications are very different things. Applications (like a JFrame) have the run of a computer, like any other application. Applets run in a very limited space called a "sandbox". Your classpath settings do not apply. The classpath that gets searched is the codebase (where your applet .class file is) and below. That's why I told you to put the class that wasn't being found in a subdirectory. Maulin may be onto something with the ARCHIVE tag, though I understood that the applet class had to be in the archive file as well. Maybe it will search the directory too. Try it. Nothing to lose.
Joined: Nov 04, 2003
Got it to work! I put the jt400.jar file in the same directory as my *.class and *.html file(s) and created a policy file that gave the applet access to all they system's resources, for testing purposes only, and made this change to my *.html file: <html> <applet code = "AS400QueryApplet.class" ARCHIVE="jt400.jar" width = "400" height = "300"> </applet> </html> All is well. Thank you all! Chad Schmidt ctschmidt