13

I'm trying to retrieve the data from the database. When I run the program it shows the error java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException I have the json-lib jar file in my WEB-INF --> lib directory, I don't know why it is showing this error for JSONArray.

My code is :

        StringBuilder sb=new StringBuilder(1024);
        sb.append("select * from ").append(uname.trim()).append("vcomments").append(" where itemid=").append(itemId).append(" and albumid=").append(albumId);
        sql=sb.toString();
        stmt = conn.prepareStatement(sql);
        ResultSet rs = stmt.executeQuery();
        //ArrayList<String> CommArray=new ArrayList();
        JSONArray arrayObj=new JSONArray();                //#100


         while(rs.next()){
            Commenter comment = new Commenter();
            comment.setUname(rs.getString("uname").trim());
            comment.setComment(rs.getString("comments").trim());
            arrayObj.add(comment.toString());

            }    
         commentObj=gson.toJsonTree(arrayObj);
         myObj.add("commentInfo", commentObj);
         out.println(myObj.toString());
         rs.close();                                                              
         stmt.close();                                                            
         stmt = null;                                                             


         conn.close();                                                            
         conn = null;                                                  

     }                 

And the console output is :

 SEVERE: Servlet.service() for servlet [VComment] in context with path [/skypark] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2904)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at skypark.VComment.doGet(VComment.java:100)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Please anyone tell me how to solve this problem......Thanks....

5
  • You are most likely missing the commons-lang jar. Feb 21, 2013 at 14:33
  • @ Sotirios Delimanolis It is not commons-lang jar problem I have that jar file..
    – user2024438
    Feb 21, 2013 at 14:40
  • @James Is it in WEB-INF/lib? And can you doublecheck that it contains the correct class?
    – millimoose
    Feb 21, 2013 at 14:58
  • @ millimoose how to check the class..
    – user2024438
    Feb 21, 2013 at 15:02
  • You are missing some JAR or another. Mar 3, 2013 at 9:12

7 Answers 7

9

I had the same Problem and - as you - I downloaded the newest commons-lang. But actually i could solve it by downloading the apache commons-lang 2.6(DDL) and put the jar under WEB-INF/lib

Hopefully you solved it in the meantime.

1
  • I have added the dependency in the pom.xml. Why should i add the jars?
    – Shruthi
    Sep 29, 2015 at 11:40
7

You are missing the commons-lang jar VERSION 2 (ie not the latest release)

The LATEST commons-lang jar VERSION 3's classes are in the package: org.apache.commons.lang3

While the OLDER commons-lang jar VERSION 2's classes are in the package: org.apache.commons.lang

1
  • For the people using build tools, this must be the accepted answer. Thank you so much! Feb 7, 2020 at 15:41
3

findjar.com suggests one of several jar files that could be missing. You should have the Apache commons-lang .jar file packaged with your solution. It should be in your .war file that you have deployed, or in your Tomcat lib directory.

If you have it (and you've confirmed that you can instantiatate/reference classes from that .jar in your solution) then perhaps it's a .jar version problem. What version of commons-lang should your JSON lib be referencing ?

Check out the JSON-lib transitive dependencies (scroll down for these)

5
  • Where do you have it ? And is it one of the versions referred to by findjar.com ? Feb 21, 2013 at 14:43
  • In my WEB-INF --->lib directory...I having commons-lang3-3.1 but findjar.com shoving commons-lang-2 what i shall do..???
    – user2024438
    Feb 21, 2013 at 14:45
  • And does it have that class in it ? What happens if you instantiate NestableRuntimeException directly in your solution ? Feb 21, 2013 at 14:47
  • NestableRuntimeException ? Perhaps your lang jar is an incompatible version re. your JSON jar Feb 21, 2013 at 14:54
  • 1
    How could I know which jar is compatible with JSON jar
    – user2024438
    Feb 21, 2013 at 14:58
2

Using net.sf.json uses the Commons Lang and in the list Brian provided (http://json-lib.sourceforge.net/dependencies.html), Commons Lang version 2.5 is specified. net.sf.json is in its current version not compatible with Commons Lang 3. For safety you should use the version specified (2.5) even though we have found that version 2.6 works fine.

The ClassNotFoundException for NestableRuntimeException is an effect of trying to use Commons Lang 3 with net.sf.json.

Since you have the Commons Lang jar in your WEB-INF/lib, all you need to do is to exchange the one you have with version 3 with the Commons Lang 2.5 (or 2.6) jar.

1

Looks like, Its can't find the org.apache.commons.lang.exception.NestableRuntimeException .

Make sure you have the commons-lang dependecy in WEB-INF --> lib .

You find it here http://commons.apache.org/lang/download_lang.cgi

1
  • My jar file contains NestableRuntimeException class. But still why it producing the error...
    – user2024438
    Feb 21, 2013 at 15:16
0

What kind of app engine are you using? I had major problems working with eclipse code engine, but I changed to Apaches Tomcat 7 and just redirected the .xml file to use the one in the app project instead.

0
0

Missing some lib (jar files)

Because of I used 'json-lib-2.4-jdk15.jar' so I have to add other require libs to use with them such as:

  • commons-beanutils-1.8.3.jar
  • commons-collections-3.2.1.jar
  • commons-lang-2.4.jar
  • commons-logging-1.1.1.jar
  • ezmorph-1.0.jar

reference link :

more detail check this out

http://json-lib.sourceforge.net

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.