AmazonServiceException NoClassDefFoundError异常

时间:2016-06-13 05:17:36

标签: hadoop amazon-web-services amazon-emr

我正在尝试编写一个EMR代码,通过它我可以连接到RedShift并执行一些查询。连接到RedSHift的代码位于EMR作业的Driver类中。

这是我的代码:

public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    String ids = getAllKeys(args[0]);
    conf.set("config", ids);

    try {
        showRedShiftTableData(); //function which will connect to Redshift server
    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon S3, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }
    //........................
    //........................
    //Other codes.

我还将此配置添加到我的pom文件中:

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk</artifactId>
    <version>1.11.7</version>
</dependency>

但是当我尝试在我的本地hadoop集群上运行代码时,我遇到了异常:

Exception in thread "main" java.lang.NoClassDefFoundError: com/amazonaws/AmazonServiceException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.apache.hadoop.util.RunJar.run(RunJar.java:214)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)

你能否告诉我可能出现的问题。

感谢。

1 个答案:

答案 0 :(得分:0)

知道了。 HADOOP_CLASSPATH未正确设置。这就是为什么hadoop没有得到罐子。