ElasticBeanstalk客户端

时间:2014-07-10 13:49:17

标签: amazon-web-services elastic-beanstalk

我尝试开发一个弹性beanstalk客户端界面,通过它连接到我的amazon帐户elasticbeanstalk。我使用了脚本文件credentials.Csl中的帐户凭据。我从Google Chrome注册了我的帐户但是我收到了错误。这是我的代码。

package PFE;


import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalk;
import com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalkClient;
import com.amazonaws.services.elasticbeanstalk.model.CheckDNSAvailabilityResult;

public class Sample {

    static AWSElasticBeanstalk      eb;

    private static void init()throws Exception{


 /*
  * The ProfileCredentialsProvider will return your [default]
  * credential profile by reading from the credentials file located at
  * (~/.aws/credentials).
  */
    AWSCredentials credentials = null;

    try {

        credentials = new ProfileCredentialsProvider().getCredentials();

    } catch (Exception e) {
        throw new AmazonClientException(
             "Cannot load the credentials from the credential profiles file. " +
             "Please make sure that your credentials file is at the correct " +
             "location (~/.aws/credentials), and is in valid format.",
             e);
    }

    eb = new AWSElasticBeanstalkClient(credentials);
    Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    eb.setRegion(usWest2);
}

public static void main(String[] args) throws Exception {

    init();    
    try {            
        CheckDNSAvailabilityResult c= eb.checkDNSAvailability(null);

        System.out.println("You have access to " + c.getAvailable() +
                           " Availability Zones.")

        eb.createStorageLocation();

    } catch (AmazonServiceException ase) {
        System.out.println("Caught Exception: " + ase.getMessage());
        System.out.println("Reponse Status Code: " + ase.getStatusCode());
        System.out.println("Error Code: " + ase.getErrorCode());
       System.out.println("Request ID: " + ase.getRequestId());
    }                  
}

}

以下是运行项目时出现的错误

 Exception in thread "main" java.lang.NoClassDefFoundError:org/apache/commons/logging/LogFactory at com.amazonaws.auth.profile.ProfilesConfigFile.<clinit>(ProfilesConfigFile.java:62) at com.amazonaws.auth.profile.ProfileCredentialsProvider.getCredentials(ProfileCredentialsProvider.java:106)
at PFE.Sample.init(Sample.java:29)
at PFE.Sample.main(Sample.java:47)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

我认为问题出在org.apache.commons.logging.LogFactory库,所以我下载了它并将其添加到我引用的库中,但我仍然遇到相同的错误。

3 个答案:

答案 0 :(得分:1)

我在尝试制作SQS示例时遇到了同样的错误...我的解决方案是:不要像外部jar一样添加AWS SDK for Java

Don't

但是作为一个图书馆。

enter image description here

答案 1 :(得分:1)

NetBeans IDE 的说明:

  1. 下载&#34; SDK for Java&#34;来自this页面

  2. 从档案馆中提取所有档案,例如在文件夹/aws-java-sdk-1.9.22

  3. 将下一个文件复制到您的项目中:

    • /aws-java-sdk-1.9.22/lib/aws-java-sdk-1.9.22.jar

    • 文件夹中的所有* .jar文件:/aws-java-sdk-1.9.22/third-party /

  4. 现在,只需在NetBeans IDE中将所有* .jar文件添加到项目中。

  5. 利润!

答案 2 :(得分:0)

问题是还有其他缺少的库,所以我为我的Eclipse Kepler安装了工具包AWS,包含所有必需的库。 http://aws.amazon.com/fr/eclipse/ ..链接下载。