使用jclouds API创建aws-ec2实例

时间:2014-04-15 07:26:18

标签: java jclouds

我正在尝试使用jclouds创建一个aws-ec2实例。在执行代码时,我得到了下面的例外

  

“java.util.NoSuchElementException:key [aws-ec2]不在提供者列表或apis:{}”中。

如何解决此异常?

1 个答案:

答案 0 :(得分:0)

您需要确保在类路径中包含aws-ec2-X.X.X.jar。要获取jar文件,您可以使用Maven pom.xml,然后执行mvn dependency:copy-dependencies -DoutputDirectory="./lib"

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <properties>
    <jclouds.version>1.7.1</jclouds.version>
  </properties>
  <name>Cloud Portability with Multi-Cloud Toolkits Workshop</name>
  <description>https://github.com/rackerlabs/multi-cloud-workshop/</description>
  <groupId>multi.cloud.workshop</groupId>
  <artifactId>multi-cloud-workshop</artifactId>
  <version>1.0</version>
  <dependencies>
    <!-- jclouds Dependencies -->
    <dependency>
      <groupId>org.apache.jclouds.driver</groupId>
      <artifactId>jclouds-slf4j</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.driver</groupId>
      <artifactId>jclouds-sshj</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.0.13</version>
    </dependency>
    <!-- Cloud Provider Dependencies -->
    <dependency>
      <groupId>org.apache.jclouds.provider</groupId>
      <artifactId>aws-ec2</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.provider</groupId>
      <artifactId>hpcloud-compute</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.jclouds.provider</groupId>
      <artifactId>rackspace-cloudservers-us</artifactId>
      <version>${jclouds.version}</version>
    </dependency>
  </dependencies>
</project>