- Applicable to JDK 6 and above
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:
Take the 2.7.0 version as an example. Follow the steps below:
Download the Java SDK aliyun_java_sdk_20170629.zip.
Unzip the SDK.
Copy the files in the unzipped folder ‘aliyun-sdk-oss-
.jar’ and 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.
When you complete the preceding steps, you can use the OSS Java SDK in Eclipse.
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.
MVN example project: aliyun-oss-java-sdk-demo-mvn.zip
Ant example project: aliyun-oss-java-sdk-demo-ant.zip
- 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.
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|