Oracle Cloud Infrastructure Documentation


Examples of SDK usage can be found on GitHub, including:

The examples are also in the downloadable .zip file for the SDK. Examples for older versions of the SDK are in the downloadable .zip for the specific version, available on GitHub.

If you'd like to see another example not already covered, file a GitHub issue.

Running Examples

  1. Download the SDK to a directory named oci. See GitHub for the download.
  2. Unzip the SDK into the oci directory. For example: tar -xf
  3. Create your configuration file in your home directory (~/.oci/config). See Configuring the SDK.
  4. Use javac to compile one of the previous example classes from the examples directory, ex:

    javac -cp lib/oci-java-sdk-full-<version>.jar:third-party/lib/* examples/
  5. You should now have a class file in the examples directory. Run the example:

    java -cp examples:lib/oci-java-sdk-full-<version>.jar:third-party/lib/* ObjectStorageSyncExample

Third-Party Dependencies and Shading

The SDK requires a number of third-party dependencies, which are available in the third-party/lib directory. To use the SDK library lib/oci-java-sdk-full-<version>.jar, all of the third-party dependencies in third-party/lib have to be on the class path.

The SDK also includes a second version of the SDK library, shaded/lib/oci-java-sdk-full-shaded-<version>.jar, which contains most of the third-party dependencies already. Only a few more third-party libraries in shaded/third-party/lib have to be on the class path when you use this version of the SDK library.

These two versions of the SDK library are functionally the same, however the second version, shaded/lib/oci-java-sdk-full-shaded-<version>.jar can simplify dealing with different versions of third-party dependencies. This is because all the dependencies that are included in shaded/lib/oci-java-sdk-full-shaded-<version>.jar were shaded, which means they will not interfere with other versions of themselves you may want to include along with this SDK.

You can use either lib/oci-java-sdk-full-<version>.jar or shaded/lib/oci-java-sdk-full-shaded-<version>.jar, but not both. When using lib/oci-java-sdk-full-<version>.jar, use all the third-party libraries in third-party/lib. When using shaded/lib/oci-java-sdk-full-shaded-<version>.jar, use all the third-party libraries in shaded/third-party/lib.

To use the shaded version of the SDK, replace the javac commands in steps 4 and 5 with the following:

  • Step 4:

    javac -cp shaded/lib/oci-java-sdk-full-shaded-<version>.jar:shaded/third-party/lib/* examples/
  • Step 5:

    java -cp examples:shaded/lib/oci-java-sdk-full-shaded-<version>.jar:shaded/third-party/lib/* ObjectStorageSyncExample