Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials

I am running the Glacier API for AWS, just a very basic version - trying to list my vaults.

I followed the example at http://docs.aws.amazon.com/amazonglacier/latest/dev/creating-vaults-sdk-java.html#creating-vaults-sdk-java-example.

I am running from the command line on Linux. It compiles fine:

javac -cp sdk/lib/aws-java-sdk-1.7.3.jar -d bin src/AmazonGlacierVaultInfo.java

But when running, I get:

java -cp "bin: sdk/lib*" AmazonGlacierVaultInfo

Exception in thread "main" java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials

It seems the SDK classes in the sdk jar are not being found.

I have my classpath correct though I think:

./:/home/name/sites/git/glacier/bin/:/home/name/sites/git/glacier/sdk/:/home/name/sites/git/glacier/src/

I run and compile from /home/name/sites/git/glacier, which has bin, src and sdk directories as detailed on http://docs.aws.amazon.com/amazonglacier/latest/dev/using-aws-sdk-for-java.html#setting-up-and-testing-sdk-java-commandline

Any help would be greatly appreciated.

like image 452
pokero Avatar asked Oct 19 '25 23:10

pokero


2 Answers

A few issues

  • Add a forward slash to parse the contents of your lib directory
  • Remove the space from the classpath
  • the surrounding quotes are unnecessary

command:

java -cp bin:sdk/lib/* AmazonGlacierVaultInfo
like image 137
Reimeus Avatar answered Oct 21 '25 14:10

Reimeus


I had the same error but i retried as below

add plugin if you also use maven:

<build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>fully.qualified.MainClass</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>

And run:

mvn clean compile assembly:single

It will packaged all dependencies required into one jar then the error will disappear.

like image 28
Gabriel Wu Avatar answered Oct 21 '25 13:10

Gabriel Wu