Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem: Using additional JAR-Files in an Applet

1 view
Skip to first unread message

Markus Reitz

unread,
Jul 18, 2003, 10:57:36 AM7/18/03
to
Hi,

my applet uses functionality that is provided by classes stored in a
separate JAR-file.

The source of my applet:
------------------------

import java.net.*;
import java.io.*;
import java.util.zip.*;

import javax.swing.*;
import JSX.*; //additional JAR-File

public class Test extends JApplet implements Serializable
{
public void write(OutputStream out)
{
System.out.println("Writing binary snapshot ...");

try
{
ZipOutputStream MyZipStream=new ZipOutputStream(out);

for(int i=0;i<10;i++)
{
MyZipStream.putNextEntry(new ZipEntry(""+i+""));

JSX.ObjectWriter MyObjectStream=new JSX.ObjectWriter(MyZipStream);

MyObjectStream.writeObject(this);
MyObjectStream.flush();
}

MyZipStream.close();
}
catch(Exception Ex)
{
Ex.printStackTrace();
}
}

public void read(InputStream in)
{
System.out.println("Reading binary snapshot ...");

try
{
ZipInputStream MyZipFile=new ZipInputStream(in);

while(in.available()!=0)
{
MyZipFile.getNextEntry();

if (MyZipFile.available()!=0)
{
JSX.ObjectReader MyObjectStream=new JSX.ObjectReader(MyZipFile);

MyObjectStream.readObject();
}
}
}
catch(Exception Ex)
{
Ex.printStackTrace(System.out);
}
}

public void init()
{
}

public void start()
{
try
{
URL url = new URL(getCodeBase(),"Test.dat");

InputStream MyStream=url.openStream();

new Test().read(url.openStream());
}
catch(Exception Ex)
{
Ex.printStackTrace(System.out);
}

System.out.println("Done.");
}

public static void main(String[] args)
{
try
{
new Test().write(new FileOutputStream("Test.dat"));
}
catch(Exception Ex)
{
Ex.printStackTrace();
}
}
}

By calling "java Test" a serialisation of instances of class Test is written
to the file "Test.dat". This file together with Test.class and
JSX2.0.9.5.jar (see http://www.jsx2.com) are stored in the _same_ directory
on the webserver. The applet should start, read the serialisation data
stored in Test.dat and then stop. But on the applet console, I get the
following error message:

Java VM version: 1.4.1_02
Java VM vendor: Sun Microsystems Inc.
Reading binary snapshot ...
java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at JSX.ObjectReader$Cache.getClass(ObjectReader.java:1503)
at JSX.ObjectReader$Cache.getClassCache(ObjectReader.java:1511)
at JSX.ObjectReader.object(ObjectReader.java:796)
at JSX.ObjectReader.readObject(ObjectReader.java:381)
at JSX.ObjectReader.readObjectOverride(ObjectReader.java:342)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:318)
at Test.read(Test.java:52)
at Test.start(Test.java:74)
at org.kde.kjas.server.KJASAppletStub$1.run(KJASAppletStub.java:102)
at java.lang.Thread.run(Thread.java:536)
Done.

If I modify the code to a "normal" application, everything works fine.

What's wrong?

Thanks in advance

Markus

0 new messages