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.
Java

Avatar of undefined
Last Comment
Lunchy

8/22/2022 - Mon
valipotor

Hi,
Please print the entire stack trace.

Regards, Vali
mb2297

ASKER
Hmm,

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

Thanks anyway,
Matt.
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?
Your help has saved me hundreds of hours of internet surfing.
fblack61
valipotor

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.
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.
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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Lunchy

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question