Running Web Applications on Oracle Cloud

This tutorial needs a review. You can edit it in GitHub following these contribution guidelines.

The Oracle Cloud is an enterprise cloud for business. The Oracle Cloud offers self-service business applications delivered on an integrated development and deployment platform with tools to rapidly extend and create new services. For more information about Oracle Cloud, see the Oracle Cloud homepage.

This document shows you how to register the Oracle Cloud with NetBeans IDE and some of the Oracle Cloud features that are supported in the IDE. This document discusses some of the advantages and disadvantages of working completely on the Cloud versus working with a local server and then deploying to the Cloud. At the end you create a simple web application, following the instructions in Introduction to Web Applications, and run it on Oracle Cloud.

You might also want to look at the Oracle Cloud Development with NetBeans and Eclipse (OEPE) series of tutorials on the Java Training Beat blog.

netbeans stamp 80 74 73
Figure 1. Content on this page applies to the NetBeans IDE 7.2, 7.3, 7.4 and 8.0

To follow this tutorial, you need the following software and resources.

Software or Resource Version Required

NetBeans IDE

7.3, 7.4, 8.0, Java EE Version

Oracle Cloud plugin

available from NetBeans Update Center via NetBeans Plugins manager

Java Development Kit (JDK)

version 7 or version 8

Oracle Java Cloud Service

Sign up at the Oracle Cloud Public Availability homepage

Oracle Java Cloud Service SDK

Download from Oracle Cloud homepage.

Oracle WebLogic server (for developing and testing applications locally)

Version indicated in chapter 4 of the Oracle Java Cloud Service Users Guide This document is available from the Resources > Documentation tab within your activated Java Cloud service.

OracleXE database server (for developing and testing applications locally)

11g

Downloading Oracle Java Cloud Service SDK

You need a local copy of the Oracle Java Cloud Service SDK to develop web applications on the Oracle Cloud. You can download the Oracle Java Cloud Service SDK from the Oracle Cloud homepage.

To download the Oracle Java Cloud Service SDK:

  1. Point a browser window to the Oracle Cloud homepage.

  2. Expand the Resources dropdown list in the main menu and click Downloads.

  3. Click Download Oracle Cloud Java Service SDK in the Oracle Java Cloud Service SDK section.

  4. On the Oracle Java Cloud Service SDK download page, read and accept the OTN License Agreement to activate the download link.

  5. Download and extract the SDK to your local system.

Install Oracle Cloud Plugin

To enable support for the Oracle Java Cloud Service in the IDE you need to install the Oracle Cloud plugin from the NetBeans Update Center. You can use the NetBeans Plugins manager to install the Oracle Cloud plugin.

Perform the following steps to install the Oracle Cloud plugin.

  1. Choose Tools > Plugins from the main menu to open the Plugins manager.

  2. Select the Available Plugins tab in the Plugins manager.

  3. Locate and select the checkbox for the Oracle Cloud plugin. Click Install.

When you click Install the IDE opens the NetBeans IDE Installer. You need to complete the steps in the installer wizard to install the plugin.

After you install the Oracle Cloud plugin the Add Cloud Provider wizard will display Oracle Cloud in the list of supported cloud providers.

Registering Oracle Cloud In the IDE

You need to register the Oracle Cloud in the IDE’s Services window before you can use it. Note that you need a separate installation of the Oracle Java Cloud Service SDK.

Note. To work with Oracle Cloud in NetBeans IDE you need to have an account on the Oracle Cloud.

To register Oracle Cloud in the IDE perform the following steps.

  1. Open the Services window in the IDE (Window > Services or Ctrl-5).

  2. Right-click the Cloud node and select Add Cloud to open the Add Cloud Provider wizard.

add cloud
  1. In the Choose Cloud field, select Oracle Cloud and click Next to open the Oracle Cloud panel.

oracle cloud1
  1. Fill in all fields. Browse for the folder containing the Oracle Java Cloud Service SDK JAR. Click Next.

When you click Next the IDE tests the connection to the cloud. A list of Cloud services appears if the connection is successful. Only the Oracle Cloud Remote server (Oracle WebLogic) is currently available.

Note: After you register an Oracle Cloud provider, you can change the Cloud details in its Properties. Open Properties by right-clicking the Oracle Cloud node and selecting Properties.

  1. Confirm that the Oracle Cloud provider is displayed in the list of Cloud resources. Click Finish.

Oracle Cloud is now listed under the Cloud node in the Services window. You can right-click the Oracle Cloud node to open a context menu that provides commands for refreshing the list of services, opening a list of jobs and logs, removing the cloud instance or viewing the cloud’s properties.

cloud contextmenu

When you register Oracle Cloud in the IDE an instance of the Oracle Cloud Remote server node also appears under the Servers node. (If it does not appear, right-click the Oracle Cloud node and select Refresh.)

registered cloud and server

You can expand the Oracle Cloud Remote node to view a list of the applications that are deployed to the remote server.

Viewing Jobs and Logs

Every request that NetBeans IDE sends to the Oracle Cloud results in a job. Every job has a status (submitted, running, failed, complete) and may have one or more log files (whitelist check log, antivirus scan log, deployment log). You can view recent jobs and their logs with the View Jobs and Logs action.

Right-click the Oracle Cloud node and select View Jobs and Logs. In the editor window, a list appears of the last 50 jobs and logs. It takes a moment to load. The jobs list does not refresh automatically. Click Refresh to refresh the list.

jobs n logs

Oracle Cloud Remote Server

Oracle Cloud Remote server is an instance of Oracle WebLogic running on Oracle Cloud. Expand the Oracle Cloud Remote node and see a list of applications running on that server. You can right-click an application to open a popup menu that contains commands for starting, stopping and undeploying the application. You can click View in the menu to open the application home page in a browser.

webapp contextmenu

To update the list of deployed applications, right-click the Oracle Cloud Remote node and select Refresh.

server contextmenu

Developing Applications on a Local Machine

We recommend developing the application on a local machine and deploying it to the Cloud periodically. While it is possible to develop a web application entirely on the Oracle Cloud, local development is preferrable for the following reasons:

  • Local deployment takes seconds on a running server. Deployment to the Cloud can take minutes.

  • Incremental deployment is only available locally.

  • Debugging is only available locally.

Risks also exist in developing locally and deploying to the Oracle Cloud, however. The application you develop locally may not run on the Oracle Cloud Remote server. For safety, develop locally on an Oracle WebLogic server 11g, which is the same server as Oracle Cloud Remote.

You must manually change the web application’s server between your local server and the Oracle Cloud server. There is no automatic way to develop locally and deploy to the Cloud periodically.

To change a web application’s server between local and Oracle Cloud:

  1. In the Projects window, right-click the application’s node and select Properties.

project contextmenu
  1. In the Project Properties, select the Run category.

run properties
  1. From the Server drop-down list, select the server you want (either Oracle Cloud Remote or local Oracle WebLogic). The server must be registered in the IDE. You can add a server by right-clicking the Servers node in the Services window.

Creating a Web Application

Go to Introduction to Developing Web Applications and complete that tutorial. Develop the web application on a local Oracle WebLogic server. After the application is complete, change the server to Oracle Cloud Remote and run the application.

Note. You need to install Oracle WebLogic Server locally and register the server with the IDE. See Video of Deploying a Web Application to Oracle WebLogic Server for more information.

Before you deploy the application to the Oracle Cloud Remote server, open the Output window (Window > Output > Output or Ctrl-4). Note the Oracle Cloud Remote Deployment tab in the output window. This tab shows you the progress of the deployment.

output cloud tab

Creating a CRUD Application with JSF

NetBeans IDE and Oracle Cloud can be used in use cases where you have an Oracle database backend that is managed through a web application hosted by Oracle WebLogic server. NetBeans IDE enables you to create entity classes for an existing Oracle database and create JavaServer Faces (JSF) pages for the resulting entity classes. This scenario requires on-premise installations of OracleXE database server and Oracle WebLogic application server.

*Important: *The Oracle Cloud Remote WebLogic server does not support JPA 2.0. If your on-premises WebLogic server is JPA 2.0-enabled, either disable JPA 2.0 or use a JPA 1.0 persistence provider for CRUD applications.

*Note: *This document gives only brief directions for creating entity classes and JSF pages. For a more detailed treatment, see Generating a JavaServer Faces 2.0 CRUD Application from a Database.

To create a CRUD Application with JSF:

  1. Enable the sample HR schema on your OracleXE database server and register the schema in NetBeans IDE. For details, see Connecting to Oracle Database from NetBeans IDE.

Use the HR username and password when you register the HR schema with NetBeans IDE.

  1. Create a Java Web Application using Java EE5 and your on-premises installation of WebLogic server. Enable the JSF framework for the application.

crudapp eevers
crudapp jsf
  1. In the Projects window, right-click the project’s root node and select New > Entity Classes from Database. The Entity Classes from Database wizard opens.

  2. In the Entity Classes from Database wizard, select New Data Source from the Data Source drop-down box. The Create Data Source dialog opens.

crudapp newdatasource
  1. Name this datasource to match the database service name in your registered Oracle Cloud account.

cloud db name
  1. Select the OracleXE HR database connection you created in Step 1. Click OK. The Create Data Source dialog closes.

create datasource
  1. In the Entity Classes from Database wizard, the Available Tables field fills with the HR schema table names. Select one of the tables, such as EMPLOYEES, and click Add. Click through the rest of the wizard, giving an arbitrary name to the package containing the entity classes and accepting all default values in other fields.

  2. In the Projects window, right-click the project’s root node and select New > JSF Pages from Entity Classes. The New JSF Pages from Entity Classes wizard opens.

  3. In the Entity Classes panel, click Select All and click Next.

  4. In the Generate JSF Pages and Classes panel, give appropriate names to the packages and JSF file folder and click Finish.

  5. In the Projects window, right-click the project’s root node and select Run. The IDE builds the project and deploys it to the on-premises WebLogic server. A browser opens on the project’s landing page.

You now have a local version of a Java web application using CRUD and JSF. You can test and tweak the application locally. When the application is in a final state, deploy it to Oracle Cloud.

Deploying the CRUD/JSF Application to Oracle Cloud

  1. In the Projects window, right-click the project’s root node and select Properties.

  2. Select the Run category in the Properties window. In this category, expand the Server drop-down list and select Oracle Cloud Remote. Click OK.

crudapp properties
  1. In the Projects window, expand the project’s Configuration Files node and double-click ` persistence.xml`. The file opens in the XML Editor’s Design view.

  2. Under Table Generation Strategy, select Create.

crudapp persistence
  1. If your on-premises WebLogic server has JPA 2.0 enabled, you must change the persistence provider from the default EclipseLink, which uses JPA 2.0, to a JPA 1.0 provider such as OpenJPA.

*Note: *If your on-premises WebLogic server is not JPA 2.0-enabled, EclipseLink falls back to JPA 1.0. In this case you do not need to change persistence providers.

  1. In the Projects window, right-click the project’s root node and select Run. The IDE builds the project and deploys it to the Oracle Cloud Remote server. You can follow the progress of deployment in the IDE’s Output window, in the Oracle Cloud Remote Deployment tab.

*Caution: *Oracle Cloud does not yet support the uploading of database tables. Therefore no data is available for your application when it is on Oracle Cloud.

Testing Whitelisting Support

Oracle Cloud does not support some standard Java API methods, such as System.exit() . The Oracle Cloud whitelist defines all methods that are allowed. During deployment of an application to Oracle Cloud, the Cloud server tests whitelist compliance. If the whitelist is violated, the Cloud server refuses to deploy the application.

NetBeans IDE helps prevent whitelist-related errors by notifying you of whitelist violations while you code. Code completion is limited by whitelisting, and whitelist violations are highlighted in the code. Run the Verify action on a web application deployed to Oracle Cloud Remote server, and the Output window shows you any whitelisting violations.

To test whitelisting:

  1. In the Projects window, right-click the web application you created and select New > Servlet. The New Servlet wizard opens.

new servlet
  1. Give the servlet an arbitrary name, select an existing package for it and click Finish. The servlet class opens in the editor.

  2. Find the servlet’s processRequest method, type System.ex in the method body and press Ctrl-Space to open code completion. Code completion does not offer you the possibility to complete System.exit because System.exit is disallowed by the Oracle Cloud whitelist. The IDE shows exit with a line through it.

cc failure
  1. Finish typing System.exit(1); . A warning appears. Scroll the cursor over the warning icon, and a tooltip appears informing you that java.lang.System.exit is not allowed.

whitelist warning
  1. In the Projects window, right-click the application’s node and select Verify. Open the Output window (Window > Output > Output or Ctrl-4). The Output window includes a Whitelist tab that shows errors due to whitelist restrictions.

whitelist output
  1. Open the Action Items window (Window > Action Items or Ctrl-6). Whitelist violations appear as a separate group of action items.

Tip: Turn on Group Action Items by Category (bottom button on left) to see whitelist violations more easily.

whitelist tasks
  1. Try to deploy the project. A warning dialog appears informing you that whitelist violations were detected and asking if you want to continue with deployment. Click No. The dialog disappears.

. In the Projects window, right-click the application’s node and select Properties. The application’s Project Properties open. Select the Whitelists category. A list of active whitelists appears. In this dialog you can disable the whitelist.

When a web application’s server is set to Oracle Cloud Remote, the Oracle Cloud whitelist applies both to that project and any of that project’s subprojects. For example, an Enterprise application set to run on Oracle Cloud Remote has the Oracle Cloud whitelist apply to the Enterprise application itself and any EJB modules or web applications that are part of the Enterprise application. Both the project and its subprojects have a Whitelist category in their Project Properties. You can use the Project Properties dialog to set whitelists separately for the project and its individual subprojects.

whitelist properties

See Also

For information about Oracle Cloud services, see the following resources:

For related information about developing web applications in NetBeans IDE, see the following resources: