我想在我的电脑上用tomcat和sesame2.7.3 api在本地创建一个SPARQL端点,我遇到了一个问题。在我的计算机上成功创建本机数据存储后,我想连接到该数据存储并在其上执行 SPARQL 查询,并且我用 Java 编写代码,我不断从 Tomcat 收到以下错误消息。
例外
javax.servlet.ServletException: Error instantiating servlet class com.jelly.web.RDFServlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:680)
根本原因
java.lang.NoClassDefFoundError: org/openrdf/repository/RepositoryException
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Class.java:2437)
java.lang.Class.getConstructor0(Class.java:2747)
java.lang.Class.newInstance0(Class.java:328)
java.lang.Class.newInstance(Class.java:310)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:680)
根本原因
java.lang.ClassNotFoundException: org.openrdf.repository.RepositoryException
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Class.java:2437)
java.lang.Class.getConstructor0(Class.java:2747)
java.lang.Class.newInstance0(Class.java:328)
java.lang.Class.newInstance(Class.java:310)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:680)
我的 Servlet 代码如下:
import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.openrdf.repository.*;
import org.openrdf.repository.config.RepositoryConfig;
import org.openrdf.repository.config.RepositoryConfigException;
import org.openrdf.repository.config.RepositoryImplConfig;
import org.openrdf.repository.manager.LocalRepositoryManager;
import org.openrdf.repository.sail.config.SailRepositoryConfig;
import org.openrdf.sail.config.SailImplConfig;
import org.openrdf.sail.nativerdf.config.NativeStoreConfig;`
public class RDFServlet extends HttpServlet {
public RDFServlet() {
super();
// TODO Auto-generated constructor stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String queryString = request.getParameter("queryInput");
// create RDF model
String DBDirectory = "/Users/ray/Documents/A04_Developer/12_PersonSearch/SesameDB";
SailImplConfig backendConfig = new NativeStoreConfig();
RepositoryImplConfig repositoryTypeSpec = new SailRepositoryConfig(backendConfig);
try
{
LocalRepositoryManager manager = new LocalRepositoryManager(new File(DBDirectory));
manager.initialize();
String repositoryID = "personV0";
RepositoryConfig config = new RepositoryConfig(repositoryID, repositoryTypeSpec);
manager.addRepositoryConfig(config);
Repository repo = manager.getRepository(repositoryID);
RDFModel model = new RDFModel(repo);
@SuppressWarnings("rawtypes")
List solutions = model.queryRDF(repo, queryString);
request.setAttribute("rdf", solutions);
RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request, response);
} catch (RepositoryException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RepositoryConfigException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}