0

I added an external jar in my eclipse dynamic webproject via Folder -> properties -> build path -> Libraries -> add external jar.

The code is working fine on compile time.

package servlet;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.tika.Tika;

@WebServlet(name="UploadServlet", urlPatterns={"/uploadFile"})     // specify urlPattern for servlet
@MultipartConfig                       //Specify that this servlet will receive a multipart data
public class UploadServlet extends HttpServlet {

    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{
        Tika tika = new Tika();

        res.setContentType("text/html");
        PrintWriter writer = res.getWriter();
        writer.write(mediaType);
    }
}

I added Apache Tika but when I run my application. these exception occured.

root cause 

java.lang.NoClassDefFoundError: org/apache/tika/Tika
    servlet.UploadServlet.doPost(UploadServlet.java:19)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause 

java.lang.ClassNotFoundException: org.apache.tika.Tika
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    servlet.UploadServlet.doPost(UploadServlet.java:19)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

I am using Apache Tika to determine what file has been upload, I want to use it for validating if a file is an image, or audio file

4

1 回答 1

0

您忘记将该 jar 添加到部署程序集页面。当您运行应用程序时,它不会部署到服务器,因此会出现 NoClassDefFoundErrors。

于 2013-07-24T23:48:21.247 回答