如何解决java.lang.ClassNotFoundException:Acme.JPM.Encoders.GifEncoder?

时间:2018-02-21 03:39:11

标签: java apache servlets classnotfoundexception imageicon

我正在研究一个简单的例子,我只是使用servlet显示图像:

public class ImageServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    response.setContentType("image/gif");  
    ServletOutputStream out = response.getOutputStream();  
    //Optain image icon
    ImageIcon icon = new ImageIcon("inbox/apple.gif");
    Image image = icon.getImage();
    new GifEncoder(image, out, true).encode();

    out.close();
}
} 

错误:

type Exception report
message Servlet execution threw an exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NoClassDefFoundError: Acme/JPM/Encoders/GifEncoder
imageChecker.ImageServlet.doPost(ImageServlet.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

如何解决此错误我在构建路径中放置了 acme.jar 提前致谢

1 个答案:

答案 0 :(得分:0)

在阅读了一些关于servlet的博客后,我找到了解决方案

Just put acme.jar and all other jar file inside the WebContent ->WEB-INF ->lib directory 并构建项目我不知道为什么在这种情况下构建路径jar文件不起作用。