1

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/jdbc/core/JdbcTemplate at com.citi.cate.svn.eers.SVNEERSFeeder.loadEmpInfoFromDB(SVNEERSFeeder.java:117) at com.citi.cate.svn.eers.SVNEERSFeeder.process(SVNEERSFeeder.java:523) at com.citi.cate.svn.eers.SVNEERSFeeder.main(SVNEERSFeeder.java:631) at resources.TheApp.main(TheApp.java:39) Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.core.JdbcTemplate at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 4 more

I am unable to find the solution for the above error. lately there was change in the spring-framework version and i changed all the jars related to the new version of spring-framework. i see the above error. tried to reload all the jars.still the error exists. please help me on this.

SVNEERSFeeder.java

line 117: JdbcTemplate jt = new JdbcTemplate(_utility.getDBConnection("csi", ""))
Tim
  • 4,286
  • 2
  • 36
  • 61
prb_cm
  • 87
  • 3
  • 13

2 Answers2

2

The exception is caused due to misconfiguration of appropriate spring jdbc jars related to the spring version. To resolve dependencies easily, you could use maven: For example, if you are using spring 4.2.5, add spring jdbc dependencies in maven as follows:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>4.2.5.RELEASE</version>
</dependency>

Apache Ivy Dependencies:

<dependency org="org.springframework" name="spring-jdbc" rev="4.2.5.RELEASE"/>
CrawlingKid
  • 961
  • 5
  • 15
0

NoClassDefFoundError Exception

This exception is thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found. This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime.

Look for differences in your build time and runtime classpaths.

In your case though, it appears that the root cause is:

resources.TheApp.main(TheApp.java:39) Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.core.JdbcTemplate at

ClassNotFoundException

It may be caused when you are trying to make a reflective call to classes at runtime, but the classes the program is trying to call does not exist.

Suparna
  • 1,062
  • 1
  • 7
  • 20
  • can you please tell me what is the best way to figure out the differences in compile time and runtime classpaths. – prb_cm Mar 28 '16 at 21:58
  • I found the following points as useful - (1) if your class C1 calls library class L1, and L1 calls library class L2, then C1 has a runtime dependency on L1 and L2, but only a compile time dependency on L1. (2) if your class C1 dynamically instantiates an interface I1 using Class.forName() or some other mechanism, and the implementing class for interface I1 is class L1, then C1 has a runtime dependency on I1 and L1, but only a compile time dependency on I1. – Suparna Mar 29 '16 at 01:38
  • could it be possible that the class is not available in the external jar that I have attached after the version of spring-framework changed? even after attaching the external sourcefile it shows that the source attachment doed not contain the source for the file jdbc Template.class – prb_cm Mar 29 '16 at 15:39