Link to home
Avatar of mb2297
mb2297

asked on

Eclipse: Export Applet complete with import jars

Hello experts,

I have written a little Java Applet which uses JAI, and I'm trying to export it so I can embed it in a webpage.

Using the File > Export > JAR file option, the exported JAR doesn't contain the neccessary JAI classes. I tried copying them into the JAr manually, but I still get java.lang.NoClassDefFoundError: com/sun/media/jai/codec/SeekableStream when I try to run the applet

My Applet class is AppFrame, in the package com.matt.ui, and it's exported into DrawingTool.jar. Here's my <applet> tag to embed it into an HTML page:

<APPLET CODE="com.matt.ui.AppFrame.class" WIDTH="100%" archive="DrawingTool.jar" HEIGHT="100%"> </APPLET>

How do I get the Applet to recognise the JAI classes?

Thanks,
Matt.
Avatar of valipotor
valipotor

Hi,
Please print the entire stack trace.

Regards, Vali
Avatar of mb2297

ASKER

Hmm,

I seem to have had a caching issue. It's working fine now.

Thanks anyway,
Matt.
Avatar of mb2297

ASKER

Actually, I'd still like to know how to include the imported jars in the export from Eclipse.

It must be relatively easy, right?
JAI just needs to be in your classpath and if it isn't it wouldn't stop the main class being found.
Suggest that you check your classpath and command line being used to execute the jar.
If using the -jar option then open it up and have a look at you manifest to check that the main class is being referenced correctly.
Avatar of mb2297

ASKER

Bear with me on this one...

The problem is somehow related to Manifest files, I think.

Running this function to load an image from a URL:

    protected RenderedImage loadImage(URL image_url) throws Exception {
          
          System.out.println("loading image from url: "+image_url);
          
        RenderedImage ret_val = null;
       
        FileCacheSeekableStream in_stream = null;
        try {                    
            InputStream input_s = image_url.openStream();
            in_stream = new FileCacheSeekableStream(input_s);
            RenderedOp rendered_op = JAI.create("stream", in_stream);
            BufferedImage in_image = rendered_op.getAsBufferedImage();  
            ret_val = in_image;
        } finally {
            if (in_stream != null) {
                in_stream.close();
            }
        }        
        return ret_val;
    }

I get this exception:

java.lang.ExceptionInInitializerError
      at com.matt.ilab.image.ImageManager.loadImage(ImageManager.java:148)
      at com.matt.ilab.image.ImageManager.setImage(ImageManager.java:73)
      at com.matt.ilab.ui.AppFrame.init(AppFrame.java:67)
      at sun.applet.AppletPanel.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)


The ExceptionInInitializerError is caused by some intitialization inside the Manifest. The problem is happening because I manually created the deployed jar file by copying the required classes into it (and not merging the Manifest information).

How do I get Eclipse (or some other tool) to create me a .jar file which has all the required dependencies and their Manifest information all together?

Thanks,
Matt.
Avatar of mb2297

ASKER

Ok, I figured this one out.

I was assuming that an <applet> tag could only take a single arguement in it's "archive" property - and therefore i needed to roll all the classes into one jar.

As it turns out you can link the applet to as many jars as you like, and it seems there is no way for eclipse to roll them all into one.

Thanks though,
Matt.
ASKER CERTIFIED SOLUTION
Avatar of Lunchy
Lunchy
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial