I am debugging a Java application that runs Groovy program for a certain database transaction call. When the pointer passes the following line of the Groovy program
sql.eachRow("select.....from...where...",[value0, value1])
It prints the following exception
- Servlet.service() for servlet Groovy threw exception
java.lang.NoClassDefFoundError: org/apache/commons/collections/CursorableLinkedList
at org.apache.commons.pool.impl.GenericObjectPool.<init>(GenericObjectPool.java:392)
at org.apache.commons.pool.impl.GenericObjectPool.<init>(GenericObjectPool.java:258)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:795)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at groovy.sql.Sql$36.run(Sql.java:1192)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.sql.Sql.createConnection(Sql.java:1190)
at groovy.sql.Sql.eachRow(Sql.java:466)
at gjdk.groovy.sql.Sql_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:115)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:119)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:187)
at sce_expiry$_run_closure1_closure4_closure5.doCall(sce_expiry.groovy:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:69)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:97)
at sce_expiry$_run_closure1_closure4_closure5.doCall(sce_expiry.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
sce_expiry.groovy is the groovy file name.
The solutions other people got recommended are like making sure the common-collections.jar and groovy-all.jar are in the classpath. I have verified. Both jar files are located in the lib folder of the webapp's directory inside my Tomcat. And the class can be found inside common-collections.jar with the same package name.
I actually have almost 0 experience with Groovy. So I'm really not sure whether some additional configuration is needed.
Does anyone have any idea?
--------------------------Solution found and question might change--------------
Alright, so I found out two ways to make this work. And they are related.
First of all, I am using Tomcat 5 here. In the Tomcat folder, there is a common/lib directory for users to place jar files shared by applications.
There are already some Apache commons-xxx.jar files in place but not commons-collection.jar. If I put a copy of commons-collection.jar together with the existing jar file, it will work! Alternatively, remove one jar file (commons-dbcp.jar), it will work as well. Both commons-collection.jar and commons-dbcp.jar are available in the application's own lib folder.
Yet, I need to do more research on this, but I suspect that commons-dbcp.jar need to work together with commons-collection.jar for the function I call, and that common/lib folder takes a higher priority to be read in. Therefore, once commons-dbcp.jar is read in, Tomcat will ingore the same in the app's lib folder and will only work with the one in the common lib folder. While commons-collection was not available in the common lib folder, it complained when commons-dbcp.jar was looking for it. Please correct me if I'm wrong. I don't know perfectly how Tomcat works..
So this question is no longer tagged with Groovy and Grails, but Java and Tomcat 5.