我正在尝试从java servlet中读取一个owl文件。但我得到了上述错误。 我以为jar文件丢失了,并试图在WEB-INF / lib中再次添加jar文件。但我仍然得到同样的错误。请帮我解决这个错误。这是servlet代码:
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
/**
* Servlet implementation class testServlet
*/
@WebServlet("/testServlet")
public class testServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public testServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
FileInputStream fis = new FileInputStream("D:/MTech/semantic validation/code/travel.owl"); String file = request.getParameter("file");
file=file.replace("\\", "/") ;
System.out.println(file);
OntModel model = ModelFactory.createOntologyModel();
model.read(fis, null);
String output = "<p>loading file done</p>";
PrintWriter out = response.getWriter();
out.println (output);
}
}
这是我得到的错误
java.lang.NoClassDefFoundError: com/hp/hpl/jena/rdf/model/ModelFactory
kanive.testServlet.doPost(testServlet.java:54)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.lang.ClassNotFoundException: com.hp.hpl.jena.rdf.model.ModelFactory
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
kanive.testServlet.doPost(testServlet.java:54)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
答案 0 :(得分:0)
最简单的解决方案是重新编译代码并重新部署(假设JAR显然位于WEB-INF/lib
文件夹中)。