Installation

Last Updated: Jul 21, 2017

Prepare the environment

  • Applicable to JDK 6 and above

Installation methods

To use the OSS Java SDK in Maven, you only need to add the corresponding dependency to the pom.xml file. Take the 2.7.0 version as an example. Add the following content to the “dependencies” tab:

  1. <dependency>
  2. <groupId>com.aliyun.oss</groupId>
  3. <artifactId>aliyun-sdk-oss</artifactId>
  4. <version>2.7.0</version>
  5. </dependency>

Method 2: Import a JAR package to your Eclipse project

Take the 2.7.0 version as an example. Follow the steps below:

  1. Download the Java SDK aliyun_java_sdk_20170629.zip.

  2. Unzip the SDK.

  3. Copy the files in the unzipped folder ‘aliyun-sdk-oss-.jar’ and all the files under the lib folder to your project.

  4. In Eclipse, right click your project and select Properties > Java Build Path > Add JARs.

  5. Select all JAR files that you have copied in Step 3.

When you complete the preceding steps, you can use the OSS Java SDK in Eclipse.

Example project

OSS Java SDK provides example projects of Maven and Ant. You can compile and run the example projects in a local device. You can also develop your own apps based on the example project.

Note:

  • Before compilation and run, modify endpoint/accessKeyId/accessKeySecret/bucketName in HelloOSS.java to your real information.
  • For project compilation and running methods, see the README.md in the project directory.

Example project

OSS Java SDK provides rich example projects for your reference or use. You can get an example project through the following two methods:

  • View in GitHub and download desired project. The src/samples under the OSS Java SDK GitHub contains the example projects.
  • Download the OSS Java SDK, such as aliyun_java_sdk_20170629.zip. Unzip the package and the “aliyun_java_sdk_20170629/samples” contains the example projects.

The example includes the following content:

Example file Example content
GetStartedSample.java Demonstrate basic Upload and Download usage
SimpleGetObjectSample.java Demonstrate Object Downloading usage
ListObjectsSample.java Demonstrate List Objects usage
DeleteObjectsSample.java Demonstrate Delete Objects by Batch usage
AppendObjectSample.java Demonstrate Append Upload usage
ObjectMetaSample.java Demonstrate Object Metadata usage
CreateFolderSample.java How to create a folder. For detailed descriptions of OSS folders, see Folders
UploadSample.java Demonstrate Resumable Upload usage
DownloadSample.java Demonstrate Resumable Download usage
ImageSample.java Demonstrate Image Service usage
PostObjectSample.java Demonstrate PostObject usage. The implementation is not dependent on the Java SDK
GetProgressSample.java Demonstrate the usage of uploading/downloading Progress Bar
CallbackSample.java Demonstrate Upload Callback usage
CRCSample.java Demonstrate uploading and downloading CRC Verification
BucketOperationsSample.java Demonstrate the bucket configuration usage, including ACL, Lifecycle, Log, Anti-leech and CORS
MultipartUploadSample.java Resumable Upload (uploadFile) is recommended directly for concurrent uploads implemented by multipart upload interface
ConcurrentGetObjectSample.java Resumable Download (downloadFile) is recommended directly for concurrent downloads implemented by download within a specified range
UploadPartCopySample.java Demonstrate the usage of multipart copy of large objects
Thank you! We've received your feedback.