Before 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?
- Access to an instance of Oracle Application Container Cloud Service (Make a note of your account information: identity domain, user name, and password.)
- Java Platform, Standard Edition (Java SE) Development Kit 8
- Play framework 2.6.x. (This tutorial was developed in Play 2.6.3, but you can use any update of this version.)
- cURL 7.0+ (cURL is installed by default on most UNIX and Linux operating systems.)
- Students application service: students-service.zip
Create the manifest.json File
- In your local system, extract the contents of the
students-service.zipfile. - Create a
manifest.jsonfile at the same level as thesbt.batfile and open it in a text editor. - 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 Variable
- In the
confdirectory, open theapplication.conffile. - Add the
http.portparameter to read thePORTenvironment variable:http.port=${?PORT} - Save the
application.conffile.
Create a Distribution Artifact
- Open a command-line window (or terminal in Linux) and go to
the
students-servicedirectory. - Start the Play console:
In Windows:sbt.bat
In Linux:./sbt - In the Play console, execute the assembly task:
[students-service] $ assembly - In a file browser, go to the
target/scala-2.11directory and verify the generated JAR file:students-service-assembly-1.0-SNAPSHOT.jar
Package an Application Archive
- Copy the
manifest.jsonfile to thetarget/scala-2.11directory. - 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 Service
- Open the Oracle Application Container Cloud Service console.
- In the Applications list view, click Create Application.
- On the Create Application page, click Java SE.
- In the Application section, enter
StudentsRestServicefor the name of your application. Click Browse. - In the File Upload dialog box, select the
students-play-service.zipfile in thetarget/scala-2.11directory, and click Open. - Keep the default values in the Instances and Memory fields and click Create.
- Click OK in the confirmation dialog box.
- After the application is created, copy the URL.
Test the Application
- Open a command-line window (or terminal in Linux).
- Create a student record and replace the
app_endpointplaceholder with the URL of your application:curl -X POST -H "Content-Type: application/json" -d "{\"name\" : \"Robert\", \"lastName\" : \"Tomson\"}" app_endpoint/students/add - Query all student entities:
curl -X GET app_endpoint/students/all
Deploy a Play Application to Oracle Cloud