wood burning stoves 2.0*
The moose likes Servlets and the fly likes NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "NoClassDefFoundError" Watch "NoClassDefFoundError" New topic


Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
I am running a servlet and it gets stuck at a certain line and shots out:
The ine above in my servlet is where it gets stuck line # 51 which is:
image = Jimi.getImage(f);
I thought it was because the JIMI jar was not in the folder, but it not it when I take that out the error gets more specific. I listed the message at the bottom. Works great for Windows just not Unix and I hae code for jpg. & GIF, it works finf for jpg. I have listed the code under the error message:
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at java.awt.Toolkit$2.run(Toolkit.java:512)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:503)
at com.sun.jimi.core.Jimi.getImage(Jimi.java:201)
at com.sun.jimi.core.Jimi.getImage(Jimi.java:190)
at gsptech.portal.servlets.ImageServlet.GIF(ImageServlet.java:51)
at gsptech.portal.servlets.ImageServlet.doGet(ImageServlet.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Ajp12Interceptor.processConnection(Ajp12Interceptor.java:221)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
package gsptech.portal.servlets;
import java.lang.*;
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.*;
import java.util.Properties;
import gsptech.portal.biz.*;
import gsptech.portal.beans.*;
import java.sql.Timestamp;
import java.net.*;
import java.awt.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import java.awt.Image;
import java.io.IOException;
import com.sun.jimi.core.*;
public class ImageServlet extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException

String file = req.getParameter("image");
int start = file.lastIndexOf('.') + 1;
int end = file.length();
String ext = "";

//Make sure that an extension exists
if (start != 0)
ext = file.substring( start, end );
System.out.println("@@@@@@@@@@@@@@@@@@@@@@" + ext);
if( ext.equalsIgnoreCase("jpg") | ext.equalsIgnoreCase("jpeg"))
JPEG(file, res);

if (ext.equalsIgnoreCase("gif"))
GIF(file, res);
private void GIF(String f, HttpServletResponse res)
{System.out.println("1ssssssssssssssssss" + f);
Image image = null;
System.out.println("2--------------------" + f);
image = Jimi.getImage(f);
System.out.println("2.555555555ssssssssssssssssss" + f);
OutputStream out = res.getOutputStream();
System.out.println("3ssssssssssssssssss" + f);
net.jmge.gif.Gif89Encoder gifenc = new net.jmge.gif.Gif89Encoder(image);
System.out.println("4ssssssssssssssssss" + f);
System.out.println("5ssssssssssssssssss" + f);
catch(Exception e)
System.out.println("Problem rendering image" + e);
private void JPEG(String f, HttpServletResponse res)

FileInputStream fis = new FileInputStream(f);

JPEGImageDecoder decode = JPEGCodec.createJPEGDecoder((InputStream)fis);

BufferedImage img = decode.decodeAsBufferedImage();

OutputStream out = res.getOutputStream();

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

System.out.println("ssssssssssssss" + f);
catch(Exception e)

System.out.println("Problem rendering image" + e);
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
It looks like you're getting the file name from a web form and using it in the getImage method. If it is working in wndows adn ot in unix it is most likely a case sensitivity issue. You might want to convert the file name passed in to all upper or lower case dependng on how they are in the file system.
hope that helps

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
I get an error message when it cannot find the file, and liek I said it works for the JPEG part just not GIF.
I agree. Here's the link: http://aspose.com/file-tools
subject: NoClassDefFoundError
Similar Threads
Displaying Images
Image Servlets
Displaying graphics in a JSP
Servlet displaying an image
Retrieve Images from oracle