Java Magazine, Jan/Feb 2017
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2017 55 cloud Optional ofNullable System getenv PORT public static final Optional String HOSTNAME Optional ofNullable System getenv HOSTNAME public static void main String args throws Exception String contextPath String appBase Tomcat tomcat new Tomcat tomcat setPort Integer valueOf PORT orElse 8080 tomcat setHostname HOSTNAME orElse localhost tomcat getHost setAppBase appBase tomcat addWebapp contextPath appBase tomcat start tomcat getServer await This code picks up the port and host name from the environment and starts the Tomcat server The rest of the code in the project is all about building the actual web application and not directly important for executing in the Oracle Application Container Cloud Build the Application Before you can deploy to Oracle Application Container Cloud Service the application must be built Right click the project name and click Build You will see in the log that Maven gets the requisite JAR files copies compiles and packages the application such that the executable JAR file is created in the target directory This file is what is often referred to as a fat JAR or an uber JAR because this JAR file includes your code as well as the dependent libraries The generated JAR includes a manifest mf file which specifies com example employees Main as the main class to run the JAR file If you run this JAR file on your local machine using the java jar employees app 10 SNAPSHOT jar withdependencies jar command you will start a Tomcat server on your local machine with your application running on it Go to http localhost 8080 in your browser and you will get a page as shown in Figure 2 Because our intent is to run the application on Oracle Application Container Cloud Service there is still some work to be done manifest json Configuration To upload and deploy the application to the cloud service you must include a manifest json file in the application archive The archive could be a zip tgz tar or gz file In the manifest json file you need to state the Java version to use and the file Figure 2 Running the web application
You must have JavaScript enabled to view digital editions.