Applicable to JDK 6 and later.
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:
2.8.2 version as an example. Follow these steps:
- Download the Java SDK version aliyun_java_sdk_20171127.zip.
- Unzip the SDK.
- Copy the files in the unzipped folder:
aliyun-sdk-oss-<versionId>.jarand all the files under the lib folder to your project.
- In Eclipse, right-click your project and select Properties > Java Build Path > Add JARs.
- Select all JAR files that you have copied in Step 3.
After you complete the preceding steps, you can use the OSS Java SDK in Eclipse.
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.
- Sample mvn project: aliyun-oss-java-sdk-demo-mvn.zip
- Sample ant project: aliyun-oss-java-sdk-demo-ant.zip
- 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’ file in the project directory.
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 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 more information about the 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 does not depend 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 using Resumable Upload (uploadFile)|
|ConcurrentGetObjectSample.java||Demonstrate how to download objects in concurrency using range-specific download. We recommend using Resumable Download (downloadFile)|
|UploadPartCopySample.java||Demonstrate operations of multipart copy for large objects|