User guide
}
catch(AmazonClientException ace)
{
System.out.println( "AmazonClientException" );
}
}
private static void displayTextInputStream(InputStream input) throws IOExcep
tion
{
// Read one text line at a time and display.
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
while(true)
{
String line = reader.readLine();
if(line == null) break;
System.out.println( " " + line );
}
System.out.println();
}
}
Open a new file, call it build.xml, and add the following lines:
<project name="Get Amazon S3 Object" default="run" basedir=".">
<path id="aws.java.sdk.classpath">
<fileset dir="./lib" includes="**/*.jar"/>
<fileset dir="./third-party" includes="**/*.jar"/>
<pathelement location="lib"/>
<pathelement location="."/>
</path>
<target name="build">
<javac debug="true"
includeantruntime="false"
srcdir="."
destdir="."
classpathref="aws.java.sdk.classpath"/>
</target>
<target name="run" depends="build">
<java classname="GetS3Object" classpathref="aws.java.sdk.classpath"
fork="true"/>
</target>
</project>
Build and run the modified program. Note that there are no credentials are stored in the program.Therefore,
unless you have your AWS credentials specified already, the code will throw AmazonServiceException.
For example:
$ ant
Buildfile: /path/to/my/GetS3ObjectApp/build.xml
build:
[javac] Compiling 1 source file to /path/to/my/GetS3ObjectApp
Version v1.0.0
33
AWS SDK for Java Developer Guide
Using IAM Roles for EC2 Instances