开发者

Servlet Throwing java.lang.ClassNotFoundException when class in path

I am writing a simple servlet and trying to create an instance of one of my classes, DataStore, in the code.

This class is public and sits in a file called DataStore.java in the same package as the Servlet code.

When I try to create a new instance in the code:

DataStore dStore = new DataStore();

I get the following exception:

java.lang.ClassNotFoundException: backend.DataStore
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    a开发者_StackOverflow中文版t backend.AjaxServlet.createGame(AjaxServlet.java:196)

I tried creating an instance of this class in a differnet file and it worked great. Any idea what could be the cause of this?


If JVM throws ClassNotFoundException the class is not found in classpath. It means that something is not configured correctly.

So, check the class (i mean file backend.DataStore.class). It's path should be: your web application folder/WEB-INF/classes/backend/DataStore.class. If this class is packaged into separate jar file this jar must be under YOUR_WEB_APP/WEB-INF/lib/yourjar.jar

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜