Before You Begin
This 15-minute tutorial shows you how to create a basic Java application on Oracle Application Container Cloud Service.
Background
Oracle Application Container Cloud Service lets you deploy Java SE, Node.js, PHP, and Python applications to the Oracle Cloud.
What Do You Need?
- Access to an instance of Oracle Application Container Cloud Service
- Java Development Kit 8 (JDK 8)
- Maven 3.0+
- Script files
Create
a Java Project
- Open a command-line window (or Terminal in Linux).
- Got to the directory where you want to store the project.
- Generate a Maven project:
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false -DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example -DarchetypeVersion=2.25.1
Prepare
the Application for Cloud Deployment
- Open the
Mainclass and update theBASE_URIvariable to use thePORTenvironment variable and the0.0.0.0host name.private static final Optional<String> port = Optional.ofNullable(System.getenv("PORT")); public static final String BASE_URI = "http://0.0.0.0:"+port.orElse("8080")+"/myapp/"; - Add the
import java.util.Optional;line. - Comment the lines:
//System.in.read(); //server.stop(); - Create the
manifest.jsonfile in your root directory project (at the same level as thepom.xmlfile) and add the following content:{ "runtime":{ "majorVersion": "8" }, "command": "java -jar simple-service-1.0-SNAPSHOT-jar-with-dependencies.jar", "release": { "build": "20170113Build", "commit": "commitString", "version": "20170113Version" }, "notes": "REST app for testing" } - Extract the content of the
scripts.zipfile in your local system. - Copy the
assemblydirectory in thesrcdirectory. - Replace the
pom.xmlfile of your project with thepom.xmlof thescripts.zipfile. - Go back to the command-line window (or Terminal in Linux), navigate to the
simple-servicedirectory, and compile and package your application.mvn compile package
Deploy
Your Application to Oracle Application Container Cloud Service
- Log in to Oracle Cloud at http://cloud.oracle.com/. Enter your account credentials in the Identity Domain, User Name, and Password fields.
- In the Oracle Cloud Services dashboard, click the Action
menu
, and select
Application Container. - In the Applications list view, click Create Application and select Java SE.
- In the Application section, enter a name for your application and click Browse.
- On the File Upload dialog box, select the
simple-service-1.0-SNAPSHOT-dist.zipfile located in thetargetdirectory and click Open. - Keep the default values in the Instances and Memory fields and click Create.
- Wait until the application is created. The URL is enabled when the creation is completed.
- Click the URL of your application and add to the end of the URL the service endpoint:
myapp/myresourceand press Enter.
Description of the illustration java-app-response.png
Want
to Learn More?
- Building and Deploying Java SE Applications on Oracle Application Container Cloud Service Learning Series
- Oracle Application Container Cloud Service in the Oracle Help Center
Deploy a Java Application to Oracle Cloud