Java quick start
Last updated: Sep-02-2024
This quick start lets you get an end-to-end implementation up and running using the Java SDK in 5 minutes or less.
Prerequisites
1. Set up and configure the library
Using a clean Java project using Maven, add the cloudinary and dotenv dependencies to the list of dependencies in pom.xml
:
Then, in your project, create a file called .env
and add the following line with your Cloudinary environment variable (replace cloudinary://<API_KEY>:<API_SECRET>@<CLOUD_NAME>
below with your own environment variable value):
In your code, include the following Cloudinary
libraries as well as the dotenv
library in your project. Copy and paste the following code into your Main.java
file:
You can now load your Cloudinary credentials from your .env file as shown below. Copy and paste the following code into your Main class:
2. Upload an image
Copy and paste the following code into a try
block within your Main class:
3. Get details of the image
4. Transform the uploaded image
5. Run your code
Run your code by clicking the Run button on the main
class.
You can use the returned image tag to display the image on your website. For now, copy and paste the URL to see the transformed image in the browser:
View the completed code
You can find the full code example for this on GitHub.
Next steps
- Learn more about the Java SDK by visiting the other pages in this SDK guide.
- Get comprehensive details about Cloudinary features and capabilities:
- Upload guide: Provides details and examples of the upload options.
- Image transformations guide: Provides details and examples of the transformations you can apply to image assets.
- Video transformations guide: Provides details and examples of the transformations you can apply to video assets.
- Transformation URL API Reference: Provides details and examples of all available transformation parameters.
- Admin API guide: Provides details and examples of the methods available for managing and organizing your media assets.