運行一個非常簡單的程序時,我得到一個「java.lang.NoClassDefFoundError:com/hp/hpl/jena/shared/BadURIException」 servlet的。該錯誤指向「Tagger」類的初始化。代碼如下所示java.lang.NoClassDefFoundError:com/hp/hpl/jena/shared/BadURIException運行servlet時
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import my.package.Tagger;
public class NormaliserServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse response) throws IOException{
Tagger pot = new Tagger("");
response.setContentType("text");
PrintWriter out = response.getWriter();
out.println("hello");
out.println(pot.someMethod());
out.close();
this.log("Request for normaliser");
}
}
戰爭文件包含WEB-INF/lib和類似調用定義「標註器」的JAR文件工作一個servlet之外。我似乎無法找到問題所在。在web.xml中是非常標準太:
<servlet>
<servlet-name>normalise</servlet-name>
<servlet-class>NormaliserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>normalise</servlet-name>
<url-pattern>/normalise</url-pattern>
</servlet-mapping>
我使用溫斯頓作爲servlet容器,但我得到確切同樣的錯誤在Tomcat中。棧跟蹤是:
java.lang.NoClassDefFoundError: com/hp/hpl/jena/shared/BadURIException
at NormaliserServlet.doGet(NormaliserServlet.java:13)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:45)
at winstone.ServletConfiguration.execute(ServletConfiguration.java:249)
at winstone.RequestDispatcher.forward(RequestDispatcher.java:335)
at winstone.RequestHandlerThread.processRequest(RequestHandlerThread.java:244)
at winstone.RequestHandlerThread.run(RequestHandlerThread.java:150)
at java.lang.Thread.run(Thread.java:619)
好吧,它似乎已經做了伎倆(我現在得到另一個錯誤),但我仍然不明白爲什麼我應該包含一個jar文件,我的應用程序實際上不使用。 Tomcat也做同樣的事情。它應該不是容器的工作來包含它需要的庫嗎?這是winstone/tomcat的設置問題嗎? – brice 2009-08-04 11:20:01
@brice:你確定你的應用程序不使用庫嗎? Tomcat當然不會,我無法想象Winstone會這樣做。 – Thilo 2009-08-04 11:22:16