Setup & Enable AWS Cloud9 for Java Development

1. Introduction

In this article, we’ll look at how to setup and configure Cloud9 environment that can support our Java and Spring Boot projects.

The AWS Cloud9 is an excellent web based generalist IDE (Integrated Development Environment) that you can use to code, build and run applications in various programming languages like Java, Node.js, JavaScript, Python, PHP, etc. It offers a coding experience with multiple languages with a built-in terminal.

The general advantages of using Cloud9 environment are –

  • Full functionality of Cloud9 is accessible over a web browser.
  • Removes the need to install and maintain a local IDE.
  • IDE comes with a terminal that includes sudo admin privileges to AWS EC2 instance that is hosting our development environment.
  • Assumes a pre-configured with AWS CLI as that assumes configured IAM role giving you easy access to AWS Services from the IDE and its terminal
  • Stays true to AWS’s pay-as-you-use model by providing configurable settings to shut down the IDE and underlying EC2 instance after certain idle time.

Additionally, AWS Cloud9 provides the following features to improve our development experience when working specifically with Java –

  • Enhanced Java language and debugging support
  • Support for smart auto completion
  • Code linting to highlight any compile time errors without the need to perform a build (similar to IntelliJ, Eclipse and other Java focused IDEs)
  • Debugging support for Java. Cloud9 allows you to set breakpoints in your code similar to other popular Java IDEs

2. Create AWS Cloud9 environment

Depending on your usage context, you’ll setup Cloud 9 as an individual, a member of a team or a member of an enterprise.

For our purpose, we will setup Cloud9 as an individual.

2.1 Create an AWS Account

To provision a Cloud9 environment, we need an AWS account. If you already have an AWS account you can skip this section.

To create an AWS account

  1. Go to https://aws.amazon.com/
aws homepage
AWS Landing page
  1. Click Sign In to the Console.
  2. Click Create a new AWS account.
Create new AWS Account

4. Follow the steps in the screens and complete the signup process. Its required to provide valid credit card details, email and mobile number.

5. You will receive a confirmation email once you successfully complete the required steps.

2.2 Provision the AWS Cloud9 environment

AWS Cloud9 environment is provisioned on top of an underlying AWS EC2 instance or our own server.

Following are the steps to provision a Cloud9 environment –

  1. Sign in to the AWS console
  2. Search Cloud9 in the services
  3. Select Cloud9 service from list, it will redirect to Cloud9 page
  4. If you’re the only one using your AWS account, you can access Cloud9 service directly by accessing the link https://console.aws.amazon.com/cloud9/.
  5. If you want to create your Cloud9 environment in any specific Region then change the region from top navigation bar. Here we are using N. Virginia (us-east-1)

6. Click Create environment button.

7. Enter Environment name and description (optional) on the page

8. Click Next Step on the screen.
It will redirect to configuration settings. Select “new EC2 instance” as the Environment type.

9. Select Instance Type and Platform.

Depending on what you want to use your Cloud9 environment for, you can select micro, small or large instance type.

For example, if you plan to use this environment as your full-fledged IDE for development purposes, you can select a small or large instance type.
On the other hand, if you plan to use this primarily to make minor changes and view code, you can select a micro instance.

10. Select Cost-saving setting
Cloud9 waits the amount of time specified in this field before shutting down the underlying Amazon EC2 instance for the environment.

11. (Optional) Expand Network settings (advanced).
Keep default VPC and Subset configuration. This is where you can create and configure your own new VPC and subnet if required.

12. Add tag if required and Click Next

13. Review and then click Create Environment

14. This may take a few minutes to complete.

Once the provisioning is complete, it’ll take you to the environment and display a Welcome page like this –

15. AWS Cloud9 service home screen looks like the below once the environment is created. You can access created Cloud9 IDE directly from here by clicking Open IDE.

Provisioned Cloud9 Environment

3. Setup & Configure Java for your Cloud9 Environment

In this section, we will install and configure Java in our newly provisioned Cloud9 environment.

1. Before installing Java, let’s check whether it is already installed or not. To check open terminal session in the AWS Cloud9 IDE, run the below command.
java --version

Checking java version on Cloud9 Terminal

In the screenshot above, we can see that Java is already installed.

2. In case Java is not installed, you can follow the below steps to install. In this example, we are installing OpenJDK 8

sudo yum -y update
sudo yum -y install java-1.8.0-openjdk-devel

sudo yum install default-jdk  // install latest JDK which available in launched instance.

sudo yum install java-11-openjdk-devel  // install open sdk 11

3. To install a particular version, run yum search command to list all the available Java packages and then yum install the required package.

> yum search all java


4. Let’s create a sample Java file to test our environment.

In the AWS Cloud9 IDE, on the menu bar, select File and New File. create a file with the following code, and save the file with the name Cloud9Test.java.

public class Cloud9Test {
   
     public static void main(String []args) {
         System.out.println("Hello, AWS Cloud9 IDE");
     }
   }

5. In the Cloud9 terminal, execute the below commands to compile and run Cloud9Test.java.

   javac Cloud9Test.java
   java Cloud9Test

At this point, our Cloud9 environment is ready for us to help manage our Java based projects, including Spring Boot.

Conclusion

AWS Cloud9 is a versatile and easily accessible cloud IDE.

In this article, we saw how to setup Cloud9 and configure it for our Java development needs.