Oracle by Example brandingDeploy a Play Application to Oracle Cloud

section 0Before You Begin

This 15-minute tutorial shows you how to prepare an application built with Play and Java and deploy it to Oracle Application Container Cloud Service.

Background

RESTful web services are typically built to run in application servers. However, application servers make the infrastructure more complex because you must properly install and configure the servers’ complicated software. You must also package and deploy the code and then compress and uncompress it before executing it.

Alternatively, you can use a simple Java application packaged as a Java Archive (JAR) file, whose main class is started from the command line. The JAR file contains not only the necessary infrastructure (dependencies and libraries) but also an embedded HTTP server for a web application. Some technologies, such as the Play framework, are deploying Java applications as simple JAR files.

What Do You Need?


Create the manifest.json FileCreate the manifest.json File

  1. In your local system, extract the contents of the students-service.zip file.
  2. Create a manifest.json file at the same level as the sbt.bat file and open it in a text editor.
  3. Add the following content and save the file:
    { "runtime":{
            "majorVersion": "8"
        },
        "command": "java -Dplay.http.secret.key=oraclejavaplay -jar students-service-assembly-1.0-SNAPSHOT.jar",
        "release": {
            "build": "20170831Build",
            "commit": "StudentsSeriveApp",
            "version": "1.0"
        },
        "notes": "Students REST API" } 

Prepare the Application to Read the PORT Environment VariablePrepare the Application to Read the PORT Environment Variable

  1. In the conf directory, open the application.conf file.
  2. Add the http.port parameter to read the PORT environment variable:
    http.port=${?PORT}
  3. Save the application.conf file.

Create a Distribution ArtifactCreate a Distribution Artifact

  1. Open a command-line window (or terminal in Linux) and go to the students-service directory.
  2. Start the Play console:

    In Windows:
    sbt.bat

    In Linux:
    ./sbt
  3. In the Play console, execute the assembly task:
    [students-service] $ assembly
  4. In a file browser, go to the target/scala-2.11 directory and verify the generated JAR file:
    students-service-assembly-1.0-SNAPSHOT.jar

Package an Application ArchivePackage an Application Archive

  1. Copy the manifest.json file to the target/scala-2.11 directory.
  2. Create an archive with the zip command:
    zip students-play-service.zip manifest.json students-service-assembly-1.0-SNAPSHOT.jar

Deploy Your Application to Oracle Application Container Cloud ServiceDeploy Your Application to Oracle Application Container Cloud Service

  1. Open the Oracle Application Container Cloud Service console.
  2. In the Applications list view, click Create Application.
  3. On the Create Application page, click Java SE.
  4. In the Application section, enter StudentsRestService for the name of your application. Click Browse.
  5. In the File Upload dialog box, select the students-play-service.zip file in the target/scala-2.11 directory, and click Open.
  6. Keep the default values in the Instances and Memory fields and click Create.
  7. Click OK in the confirmation dialog box.
  8. After the application is created, copy the URL.

Test applicationTest the Application

  1. Open a command-line window (or terminal in Linux).
  2. Create a student record and replace the app_endpoint placeholder with the URL of your application:
    curl -X POST -H "Content-Type: application/json"  -d "{\"name\" : \"Robert\", \"lastName\" : \"Tomson\"}" app_endpoint/students/add  
  3. Query all student entities:
    curl -X GET app_endpoint/students/all 

More informationWant to Learn More?