Developing an Enterprise Application for Oracle WebLogic ServerThis tutorial demonstrates how to use the IDE to create a web application that uses JavaServer Faces (JSF) 2.x and the Java Persistence API (JPA) 2.0 and then deploy the application to the Oracle WebLogic Server. In this tutorial you will register the WebLogic Server with the IDE, and then use wizards in the IDE to create a JDBC resource and entity and bean classes. You will then use the IDE to deploy the application to the server and register the new datasource. Contents ![]() To follow this tutorial, you need the following software and resources.
Notes.
Registering the Oracle WebLogic ServerIn this tutorial you will deploy a web application to the Oracle WebLogic Server. To deploy applications to the WebLogic Server from the IDE, you need to register an instance of the server with the IDE. This section describes how to use the Add Server Instance wizard in the IDE to register an instance of the WebLogic Server. Downloading and Installing the ServerBefore you can register the server, you need to download the WebLogic Server installer and follow the steps described in the Oracle WebLogic Server installation guide to install the server on your local machine. In addition to installing the server, you will need to create a WebLogic domain before you can register the server with the IDE.
You might want to look at the following sections of the WebLogic Server Installation Guide for details on installing and setting up the server. Registering the Server with the IDEAfter you install the server, you can use the Add Server Instance wizard to register an instance of the server by specifying the server domain.
![]() When you click Finish, the Oracle WebLogic Server will appear under the Servers node in the Services window. You can right-click the Oracle WebLogic Server node to perform various actions, including the following:
![]() Opening the Admin ConsoleIn this exercise you will open the Admin Console for the WebLogic Server in your browser. The Admin Console enables you to configure the server settings and view the deployed applications and available resources.
After you log in, you will see the Home Page of the Admin Console in your browser. ![]() Enabling Support for JPA 2.0 on Oracle WebLogic Server 11gIf you are using Oracle WebLogic Server 11g (10.3.4, 10.3.5) you need to enable support for Java Persistence API (JPA) 2.0 and set the default persistence provider to TopLink. Oracle WebLogic Server 11g is a Java EE 5 container and is JPA 1.0 and JPA 2.0 compliant. JPA 1.0 is enabled by default when you install Oracle WebLogic Server 10.3.4 and 10.3.5, but the WebLogic Server installation includes the necessary files to support JPA 2.0. You can enable JPA 2.0 for the WebLogic Server when you register the server instance or in the Servers manager in the IDE. Alternatively, you can follow the steps for Using JPA 2.0 with TopLink in WebLogic Server in the WebLogic Server documentation. The WebLogic Server supports Java Persistence API (JPA) and comes bundled with the Oracle TopLink and Kodo persistence libraries. In this exercise you will change the default persistence provider from Kodo to Oracle Toplink in the Admin Console of the WebLogic Server. Note. TopLink and JPA 2.0 support are enabled by default when you install WebLogic Server 12c. To enable support for JPA 2.0 in the Servers manager and set the default persistence provider, perform the following steps.
![]() When you click Save, Oracle TopLink will be the default persistence provider for applications deployed to the server when no persistence provider is explicitly specified by the application. Note. The application in this tutorial will use the Java Transaction API (JTA) to manage transactions. JTA is enabled by default when you install WebLogic. You can modify the JTA settings in the JTA tab in the Configuration tab for the domain. Creating the Web ApplicationIn this tutorial you will create a Java EE web application. The web application will contain entity classes that are based on tables in the sample database. After you create the connection to the database, you will create a persistence unit and use a wizard in the IDE to generate entity classes from the database. You will then use a wizard to create JSF pages based on the entity classes. Creating the ProjectIn this exercise you will use the New Project wizard to create a web application and specify the Oracle WebLogic Server as the target server.
When you click Finish, the IDE creates the web application project and opens index.xhtml in the editor. In the Projects window you can see that the IDE created the weblogic.xml descriptor file and web.xml under the Configuration Files node. ![]() If you open web.xml in the editor you can see that faces/index.xhtml is specified as the default index page. If you open weblogic.xml in the editor the file will be similar to the following. <?xml version="1.0" encoding="UTF-8"?> <weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"> <jsp-descriptor> <keepgenerated>true</keepgenerated> <debug>true</debug> </jsp-descriptor> <context-root>/WebLogicCustomer</context-root> </weblogic-web-app> Notes.
Creating the Database ConnectionThis tutorial uses a database that is named sample and running on the MySQL database server. In this exercise you will use the IDE to create the database and populate the database tables. You will then open a database connection to the database. The IDE will use the database connection details to create the persistence unit for the application. For more details about using a MySQL database server with the IDE, see the Connecting to a MySQL Database tutorial Note. Alternatively, if you installed the GlassFish server when you installed the IDE, you can use the database connection to the sample database on the JavaDB database server that was registered automatically during the IDE installation. In this exercise you will create and open a connection to the database.
When you click Connect, a database connection node for the database appears under the Databases node. You can expand the node to view the database tables. ![]() The IDE uses the database connection to connect to the database and retrieve the database details. The IDE also uses the details from the database connection to generate the XML file that the WebLogic Server uses to create the data sources on the server and identify the appropriate drivers. If you do not have a MySQL database installed, you can use the sample database running on JavaDB. If the sample database does not exist, you can right-click the MySQL (or JavaDB) node and choose Create Database. For more details see Connecting to a MySQL Database tutorial. Creating the Persistence UnitTo manage persistence in the application you only need to create a persistence unit, specify which data source and entity manager to use, and then let the container do the work of managing entities and persistence. You create a persistence unit by defining it in persistence.xml. Note. For the purpose of demonstration, in this exercise you will use the New Persistence Unit wizard to create the persistence.xml file. The wizard will help you specify the properties of the persistence unit. You can also create a persistence unit in the New Entity Class from Database wizard. If no persistence unit exists, the wizard provides the option to create a persistence unit for the project. The wizard will create a persistence unit that uses the WebLogic Server default persistence provider.
![]() When you click Finish, persistence.xml is created for your project and opens in the editor. You can click Source in the toolbar of the editor to open persistence.xml in the XML source editor. This file contains all the information the server needs to manage the entities and persistence of the application. Note. If you are not using an existing datasource, the IDE will generate an XML file under the Server Resources node (for example, datasource-1-jdbc.xml) that contains the details that are used to create the datasource on the server, including the JDBC driver for the database. If you open persistence.xml in the XML source editor, you can see that the IDE specified the persistence version as 2.0 and that the schema as persistence_2_0.xsd. The IDE specifies org.eclipse.persistence.jpa.PersistenceProvider as the persistence provider in persistence.xml. EclipseLink is the primary persistence implementation for Oracle TopLink and the reference implementation of JPA. <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="WebLogicCustomerPU" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>jdbc/mysql-sample</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="eclipselink.ddl-generation" value="create-tables"/> </properties> </persistence-unit> </persistence> You can also choose TopLink in the wizard, in which case the wizard will specify oracle.toplink.essentials.PersistenceProvider as the persistence provider in persistence.xml. The IDE will add the Oracle TopLink Essentials - 2.0.1 libraries to the classpath. In current and future versions of Oracle TopLink, Oracle TopLink Essentials is replaced by EclipseLink. Where possible, you should choose to use Oracle TopLink/EclipseLink instead of Oracle TopLink Essentials. Creating the Entity ClassesYou will now use the Entity Classes from Database wizard to create the entity classes based on the relational database.
When you click Finish, the IDE generates entity classes for each of the selected tables. You can expand the ejb source package node to view the generated entity classes. Generating JSF PagesIn this exercise you will use a wizard to generate JSF pages based on the existing entity classes.
When you click Finish, the IDE generates JSF 2.0 pages and controller and converter classes for the JSF pages. The IDE generates a set of JSF pages for each entity class in the default Web Pages directory. The IDE also generates a managed bean class for each entity that accesses the corresponding session facade class for the entity. Running the ProjectIn this exercise you will build and deploy the web application to the WebLogic Server. You will use the Run command in the IDE to build, deploy and launch the application.
When you click Run, the IDE builds the project and deploys the WAR archive to the WebLogic Server and creates and registers the new JDBC datasource. The welcome page of the application (http://localhost:7001/WebLogicCustomer/) opens in your browser. ![]() If you log in to the Admin Console, you can click Deployments in the Your Deployed Resources section to see a table with the resources that are currently deployed to the server. ![]() You can click the name of each of the resources to view additional details about the resource. You can also delete resources in the Deployments table. Notes about deploying to WebLogic Server 10.3.4 or 10.3.5.
For more information about deploying applications, see Deploying Applications to WebLogic Server See AlsoFor more information about using NetBeans IDE to develop web applications using Java Persistence and JavaServer Faces, see the following resources: |
Documentation |