问题描述
我通过文件夹在我的日食动态webproject添加外部JAR - >属性 - >构建路径 - >库 - >添加外部罐子。
I added an external jar in my eclipse dynamic webproject via Folder -> properties -> build path -> Libraries -> add external jar.
在code是编译时工作正常。
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);
}
}
我添加的Apache提卡但是当我运行我的应用程序。这些出现异常。
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)
我使用Apache提卡,以确定哪些文件已被上传,我想如果一个文件是图像,或者用它来验证音频文件
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
推荐答案
您忘了那个jar添加到部署大会页面。当你运行你的应用程序,因此NoClassDefFoundErrors这不是部署到服务器。
You forgot to add that jar to the Deployment Assembly page. It's not deployed to the server when you run your application, hence the NoClassDefFoundErrors.
这篇关于使用外部罐当Eclipse朱诺EE的NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!