java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22330903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials
提问by pokero
I am running the Glacier API for AWS, just a very basic version - trying to list my vaults.
我正在为 AWS 运行 Glacier API,只是一个非常基本的版本 - 试图列出我的保险库。
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:
我在 Linux 上从命令行运行。它编译得很好:
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.
似乎没有找到 sdk jar 中的 SDK 类。
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
我从 /home/name/sites/git/glacier 运行和编译,其中包含 bin、src 和 sdk 目录,详见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.
任何帮助将不胜感激。
采纳答案by Reimeus
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
- 添加正斜杠以解析
lib
目录的内容 - 从类路径中删除空格
- 周围的引号是不必要的
command:
命令:
java -cp bin:sdk/lib/* AmazonGlacierVaultInfo
回答by Gabriel Wu
I had the same error but i retried as below
我有同样的错误,但我重试如下
add plugin if you also use maven:
如果您还使用 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.
它将所需的所有依赖项打包到一个 jar 中,然后错误就会消失。