Installation

Last Updated: Dec 05, 2017

Prepare the environment

Applicable to JDK 6 and later.

Install

To use the OSS Java SDK in Maven, you only need to add the corresponding dependency to the pom.xml file. Take the 2.8.2 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.8.2</version>
  5. </dependency>

Method 2: Import a JAR package to your Eclipse project

Take the 2.8.2 version as an example. Follow these steps:

  1. Download the Java SDK version aliyun_java_sdk_20171127.zip.
  2. Unzip the SDK.
  3. Copy the files in the unzipped folder: aliyun-sdk-oss-<versionId>.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 previous steps, you can use the OSS Java SDK in Eclipse.

Sample project

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

Note:

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

Sample program

OSS Java SDK provides a variety of sample programs for your reference or use. You can get a sample program through the following two methods:

  • In Github, view and download the OSS Java SDK github. The src/samples directory under it contains sample programs.
  • Download the OSS Java SDK, such as aliyun_java_sdk_20171127.zip. Unzip the package and the aliyun_java_sdk_20171127/samples contains the sample programs.

The sample includes the following content:

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