0

I'm using tomcat 5 and JSON parser net/sf/json. I import json-lib2.4-jdk15.jar in my project and add it to `common/endorsed' dir in my tomcat. But when I start my servlet I have this exception:

java.lang.NoClassDefFoundError: net/sf/json/JSONException
net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:108)
net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:84)
com.britecs.atajer.bl.json.SubCategories.getSubCategory(SubCategories.java:37)
com.britecs.atajer.pl.json.SubCategoriesServlet.doGet(SubCategoriesServlet.java:23)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Can someone help me?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
nyanev
  • 11,299
  • 6
  • 47
  • 76

1 Answers1

3

I'm not sure 'tomcat/common/endorsed' is the right directory to be using. Have you tried installing your JAR file in tomcat/lib?

aroth
  • 54,026
  • 20
  • 135
  • 176
  • 1
    I don't see no reason for putting it directly in a Tomcat directory anywhere. Jar files belong to the WEB-INF/lib directory of your project which is deployed file by file or with a _war_ file to Tomcat. – Codo Jul 20 '11 at 11:44
  • 1
    @Codo - Good point. The JAR could be placed under `WEB-INF/lib` as part of the build process, which would also work, and which makes the compiled WAR file more portable. Typically the Tomcat directories are uses for JAR files that are needed by multiple webapps running on the same server, which doesn't appear to be applicable here. However, a JSON parser is a good example of a library that multiple webapps are likely to all require. – aroth Jul 20 '11 at 11:50
  • That's true as long as all the applications use exactly the same version. Once they require different versions of the same library, the small advantage of saving a few bytes turns into a severe disadvantage of defunct web applications. – Codo Jul 20 '11 at 12:10