Oracle by Example brandingDeploy a Tomcat Web Application to Oracle Cloud

section 0Before You Begin

This 15-minute tutorial shows you how to prepare a Java web application (built with Tomcat as the embedded server) and deploy it to Oracle Application Container Cloud Service.

Background

Oracle Application Container Cloud Service provides a lightweight infrastructure so that you can run Java Platform, Enterprise Edition (Java EE), Java Platform, Standard Edition (Java SE), PHP, Python, Node.js, and Ruby applications in Oracle Cloud.

What Do You Need?


section 1Prepare Your Application for Cloud Deployment

  1. Extract the contents of the employees-web-app.zip file to your local system.
  2. Create a manifest.json file at the same level as the pom.xml file and open it in a text editor.
  3. Add the following content and save the file:
    {
        "runtime": {
            "majorVersion": "8"
        },
        "command": "java -jar employees-app-jar-with-dependencies.jar",
        "notes": "Employees Web Application with Tomcat embedded"
    } 
  4. Open the src\main\java\com\example\employees\Main.java file in a text editor and add the following code:
    • Import the Optional class:
      	import java.util.Optional;
    • Create a PORT instance variable:
      	public static final Optional<String> PORT = Optional.ofNullable(System.getenv("PORT"));
    • Use this PORT variable to set the port on the Tomcat instance:
      	tomcat.setPort(Integer.valueOf(PORT.orElse("8080") ));

section 2Compile and Package Your Application

  1. Open a command-line window (or terminal in Linux) and go to the employees-web-app directory.
  2. Compile and package your application:
    mvn compile package

section 3Deploy Your Application to Oracle Application Container Cloud Service

  1. In a web browser, go to https://cloud.oracle.com/home and click Sign In.
  2. From the Cloud Account menu, select Traditional Cloud Account, select your data center, and click My Services.
  3. Enter your identity domain and click Go.
  4. Enter your cloud account credentials and click Sign In.
  5. In the Oracle Cloud My Services dashboard, click Action Action menu icon and select Oracle Application Container Cloud Service.
  6. In the Create Application dialog box, in the Applications list view, click Create Application and select Java SE.
  7. In the Application section, enter EmployeeApplication for the name of your application. Click Browse.
  8. In the File Upload dialog box, select the employees-app-dist.zip from the employees-web-app/target directory and click Open.
  9. Keep the default values in the Instances and Memory fields and click Create.

section 4Test the Application

  1. After the application restarts, click the URL for your application.
    Response of the EmployeeApplication for Employees
    Description of the illustration employee_app_response.png
  2. Click New Employee, enter values in the Name, Last name, Birthdate, Role, Department, and E-mail fields, and click Accept.
  3. Click the ID number, update the employee information, and click Accept.
  4. To delete the employee, click Delete button.

more informationWant to Learn More?