13

Im trying to run the DynamoDB sample that comes with the AWS SDK for java. Im doing it using eclipse, and added the aws-java-sdk-1.3.2.jar file to the build path of the project. Compilation of course goes fine, but im getting a runtime exception named NoClassDefFoundError. I know it means that the class was there at compilation but couldn't be found at runtime. I tried adding the jar file to env variables - didn't help. I also checked and there is no problem using other external jar files on other projects. Same problem on both windows and linux.

help anyone?

Thanks, ben.

Stack Trace:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at com.amazonaws.services.dynamodb.AmazonDynamoDBClient.<clinit>(AmazonDynamoDBClient.java:62)
    at AmazonDynamoDBSample.init(AmazonDynamoDBSample.java:62)
    at AmazonDynamoDBSample.main(AmazonDynamoDBSample.java:67)
Lai Xin Chu
  • 2,462
  • 15
  • 29
Ben Danon
  • 176
  • 1
  • 1
  • 11

2 Answers2

15

Inside the aws-java-sdk-1.3.2 folder you will find another folder named "third-party". All the third-party files used by Amazon SDK are inside that folder, including Apache Common Logging. You have to add the required files to your classpath along with AWS SDK jar files.

Pedro Aurélio
  • 151
  • 1
  • 4
  • Could you provide a web link to that magic "third-party"? In the jar dependency there is no such folder. – Cherry Apr 20 '17 at 08:06
  • 1
    Omg... I've been circling this exact problem for way to long... Third Party Libraries... son of a... – WernerCD Jul 13 '17 at 06:34
2

It looks like your AWS JAR needs a few extra JARs to implement used, but non-AWS items (like in your case logging).

If you downloaded a distributable that contains a "lib" directory, odds are you only configured Eclipse to use the AWS JAR instead of all the required JARs, including AWS and probably all the JARs in the "lib" directory.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • lib had aws-java-sdk-1.3.2-sources.jar and aws-java-sdk-1.3.2-javadoc.jar in it. They are not relevant right? i also got a directory called third party, this one contained a commons-logging-1.1.1.jar and it is also in the build path... – Ben Danon Jun 13 '12 at 16:27
  • You are right in guessing that the sources and javadoc jars are not what you need to add. The third-party commons-logging-1.1.1.jar file contains the missing class you seek. As an aside, you can configure the AWS library to "include source" and then hook up the "sources" JAR file if you want to debug into the aws library. – Edwin Buck Jun 13 '12 at 16:29
  • commons-logging-1.1.1.jar is already inside the build path. i also found org/apache/commons/logging/LogFactory.class manually inside the jar. can you think of any reason why the JVM would not find it? – Ben Danon Jun 13 '12 at 16:44
  • Probably your runtime path is different than your build path. Check the run configuration to see if it also includes the commons-logging jar file. – Edwin Buck Jun 13 '12 at 16:45
  • 3
    You were right! The build path should contain aws-java-sdk-1.3.2.jar and the RUNTIME path (bootstrap entries) should contain jackson-core-asl-1.8.7.jar, httpclient-4.1.1.jar , httpcore-4.1.jar, commons-logging-1.1.1.jar, commons-codec-1.3.jar. – Ben Danon Jun 13 '12 at 17:22
  • I continue to run into this issue irregularly. Using Maven, I have all the right JARs on the build path, but sometimes I need to explicitly update he classpath, which is a pain when using many JARs. Is there a way in eclipse to automatically put build path JARs onto class path? (I thought that's what it did already...) – Don Cheadle Oct 23 '14 at 04:02