4

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.

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, tried that but same result: java -cp "bin: sdk/lib/*" AmazonGlacierVaultInfo. I get java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials etc....
I hadn't spotted that actually - thanks very much, that was it.
1

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.

Comments

0

I had the same issue and it worked for me.

Add following to the pom.xml

    <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>

Then go to target folder to see the name of jar file. It will look something like this aws-java-sdk-1.7.3-SNAPSHOT-jar-with-dependencies.jar Then come out of target folder and run

java -cp sdk/lib/name-of-jar-file-found-inside-target-folder -d bin src/AmazonGlacierVaultInfo

name-of-jar-file-found-inside-target-folder will look something like this aws-java-sdk-1.7.3-SNAPSHOT-jar-with-dependencies.jar

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.