harunpehlivan / cld-intro-java

Intro to Cloudinary Using Java

Home Page:https://cloudinary-training.github.io/cld-intro-java/uw.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Introduction to Cloudinary Using Java

This repository is used in conjunction with the Cloudinary training course Introduction to Cloudinary Using Java.

Setup

Java

The Cloudinary Java SDK will run on Java 6 and any higher version. For purposes of training, we are using Java Version 8.

Maven

The Cloudinary libraries are made available with Maven. This repo includes a project configured with Cloudinary libraries.

We are supplying a pom.xml file. You'll find these dependencies have been added to support this training.

  • com.cloudinary.cloudinary-taglib produce custom tags
  • com.cloudinary-http44 Apache 4.4 integration
  • com.google.code.gson format JSON output
  • junit testing

See Cloudinary Documentation on Maven for more information about Cloudinary Maven libraries.

For many IDE's like Visual Studio Code, you won't need to install Maven. They will take care of importing the library and plugin dependencies.

IDE

We present this content using IntelliJ IDEA or Java in Visual Studio Code.

You may import the Java code used into your favorite IDE. You'll find the Main.java in repo in the folder src/main/java/cld_intro_java/. This is the entry point to static "runners" that contain code to help you upload, manage and transform your media.

Install Java

You can find instructions for downloading and installing Java for many environments.

Verify your version of Java is 6+

java -version

Sample output for Version 8

$ java -version
java version "1.8.0_311"
Java(TM) SE Runtime Environment (build 1.8.0_311-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.311-b11, mixed mode)

Executing Code

Providing Cloudinary Credentials

You will need to register for a free Cloudinary account in order to work along with this training. It is recommended that you create a training account for this training to keep this work separate from any work you do in a production Cloudinary account. You only need an email address that can be verified to set up this account.

Cloudinary provides 3 credentials for developers to use in interacting with SDK's and Widgets:

  1. CLOUD_NAME
  2. API_KEY
  3. API_SECRET

CLOUD_NAME and API_KEY can be revealed without creating any security issues, but you must keep API_SECRET private. Don't check it into GitHub and don't include it in blog posts.

CLOUDINARY_URL

Cloudinary provides CLOUDINARY_URL as an environment variable KEY. You can copy the full value in your console. Click on the Copy to Clipboard link to copy the full URL into your clipboard. The format of the CLOUDINARY_URL is cloudinary://API_KEY:API_SECRET@CLOUD_NAME. This environment variable, therefore, encapsulates all of the Cloudinary credentials.

CLOUDINARY_URL

Using IntelliJ

Edit Configuration

Edit Configuration

Add Environment Variables

Add Environment Variables

Using VS Code with Java Extensions

Add Java Extension pack to your VS Code installation: Java Extensions for VS Code. Add CLOUDINARY_URL to a .env key in the .vscode/launch.json. We have git ignored .vscode, so your API_SECRET will not get checked in.

Adding Credentials to .vscode/launch.json

You will see run | debug links above the main method in main.java. Click run to execute.

Run Java in VS Code

Code Runners

The Cloudinary library is instantiated with credentials in src/main/java/cld_intro_java/Main.java. Code in the other module files is called with a static runner function.
Map results are formatted in the console using a static function in src/main/java/cld_into_java/CourseUtils.java named jsonPrint. This function takes a Map interface parameter and uses the com.google.gson.GsonBuilder library to "pretty print" the data as JSON.

You will be controlling output by uncommenting modules in Main.java and lines of code in the other java files. This is to provide focus on concepts as they are presented.

Assets

All local assets used in training, are located in the ./assets directory

About

Intro to Cloudinary Using Java

https://cloudinary-training.github.io/cld-intro-java/uw.html

License:MIT License


Languages

Language:Java 85.0%Language:HTML 12.0%Language:CSS 3.0%