How To Run Java Application On Amazon EC2?

397 Views
0 rating based on 0 reviews

Are you looking to Run Java Application on Amazon EC2? Are you worried that your application might stop responding, just like one of my applications did? Then you are at the right place. Today I will be telling you how you can run java applications on Amazon EC2.

Run Java Application on Amazon

Amazon Elastic Compute Cloud (Amazon EC2) is a web maintenance tool that offers shielded adaptable compute space in the cloud. Java is a programming dialect that is constructed for making a Java application. Now, for running a Java application on Amazon EC2, you have to gain some basic knowledge about Java and Amazon Web Services. In this article, we will use the Spring Petclinic application to run on Amazon EC2. So, follow us to know about how to run Java application on Amazon EC2.

Running Java Application on Amazon EC2

  1. First, create an Amazon Web Services account if you do not have it. Create it from here – Sign Up. You can have a free account for twelve-month without paying.
  2. Then, set up the EC2 instance. Open the AWS management console.  Click on “Launch a virtual machine”.
  3. Then choose your required AMI from the Amazon Machine Image window. Here you will find various AMI.  We chose the “Amazon Linux AMI”. Because it can run a Java application. 
  4. Next, choose your instance type. There is only one free tier eligible type, which is the “t2.micro” type. Select it.
  5. Choose all the default configurations for the instance. If you have more requirements in the configuration, then you can change it as you wish. Proceed by clicking “Review and Launch”.
  6. Then, review all the settings from the preview window and select “Launch”. Next, the key pair window will appear. You may pick a current key pair or make a new one. Make a new one and download it. Transfer the key pair file to the “.ssh” folder. Finish it by clicking “Launch Instances”.
    preview window and select Launch
  7. Select “Connect” from the top toolbar. It will give you three choices to connect your instance. Apply a single SSH client.
    Connect to Your Instance
  8. After ensuing the command, the text given on the picture will appear on the window. As you are going to run a Java application, first examine the Java version. If the Java version is old fashioned, update it by installing “sudo yum Java”.
    Appeared text
    Update Java version using this
  9. Then, proceed to add the Java application and server. We chose the “Spring Petclinic” application and “Tomcat” server. You may upload both the server and the application simultaneously. Attach the “petclinic.war” to the “webapps” file and compress it. You can find it on the Tomcat server.
    Attach to webapps folder
  10. Run the command given on the picture to upload the whole tomcat package. Extract the folder, after finishing the uploading process of the package. You have to exchange the file path with the appropriate path.
    whole tomcat package
  11. Link to the EC2 instance and access the terminal window. Then, navigate to the Tomcat bin folder. Apply the given command:
    Apply this command
  12. Your work is complete now. The Spring Petclinic is used for running a Java application on a Tomcat server.
  13. Additionally, you may analyze the project. Navigate to “AWS Instance”. There, you will find the Public DNS(IPv4) value. Copy it. Then, open your computer browser and go to the copied link.
  14. Now, you can observe the application on the browser. If you can not open the application, make sure that your instance has “ALL TCP” on it. Also, fix the port extent to the maximum.

So, following these steps, you can run a Java application on Amazon EC2 effortlessly.

Summary: Run Java Application on Amazon EC2

  • Creating the Amazon EC2 instance.
  • Connecting to the Amazon EC2 instance using SSH.
  • Installing Java on the Amazon EC2 instance.
  • Configuring Java Environment on the Amazon EC2 instance.
  • Create a Simple Java Program and Compile it on the Amazon EC2 instance.
  • Run the Java Program on the Amazon EC2 instance and display output online.