How to Change Jdk Version in Weblogic 10.3 6

In 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 Project

In this exercise you will use the New Project wizard to create a web application and specify the Oracle WebLogic Server as the target server.

  1. Choose File > New Project (Ctrl-Shift-N; ⌘-Shift-N on Mac).

  2. Select Web Application from the Java Web category. Click Next.

  3. Type WebLogicCustomer for the project name and specify the project location.

  4. Deselect the Use Dedicated Folder option, if selected. Click Next.

  5. Select Oracle WebLogic Server from the Server dropdown list.

  6. Select Java EE 5 or Java EE 6 Web as the Java EE Version. Click Next.

Note. Java EE 6 Web is only available if you registered an instance of WebLogic Server 12c.

new project ee6

Figure 7. Weblogic selected in New Project wizard

  1. Select JavaServer Faces framework.

  2. Select JSF 2.x from the Server Library dropdown list. Click Finish.

projectwizard serverlib

Figure 8. Frameworks panel New Project wizard

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.

wl projects window1

Figure 9. weblogic.xml selected in Projects window

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.

  • If the weblogic.xml file contains the <fast-swap> element, confirm that fast-swap is disabled by confirming that the value for the <enabled> element is false.

                              <fast-swap>         <enabled>*false*</enabled>     </fast-swap>            
  • If the target server is WebLogic Server 11g (10.3.4 or 10.3.5), the server installation includes the libraries necessary for using JSF 1.2 and JSF 2.x in your applications but they are deactivated by default. You need to deploy and install the JSF 2.x libraries before you can start using the libraries. If the library is not already installed, the IDE will prompt you and can install the library for you if you choose the library in the New Project wizard. The library only needs to be installed once.

install libraries dialog

Figure 10. Resolve Missing Server Library dialog

After you create the application, when you view the weblogic.xml descriptor file you can see that the IDE modified the file to specify the JSF library that will be used with the application.

              <?xml version="1.0" encoding="UTF-8"?> <weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90" xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">   <context-root>/WebLogicCustomer</context-root>   *<library-ref>       <library-name>jsf</library-name>       <specification-version>2.0</specification-version>       <implementation-version>1.0.0.0_2-0-2</implementation-version>       <exact-match>true</exact-match>   </library-ref>* </weblogic-web-app>            

Creating the Database Connection

This 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.

  1. Right-click the MySQL Server node in the Services window and choose Connect.

  2. Type the user name and password. Click OK.

  3. Right-click the MySQL Server node and choose Create Database.

  4. Select sample in the New Database Name dropdown list. Click OK.

create db

Figure 11. Create Database dialog box

Note. Depending on how you configured your database, you may need to explicitly specify access permissions for the new database.

When you click OK, the IDE creates the sample database and populates the database tables. If you expand the MySQL server node you can see that the list of databases now contains the new sample database.

  1. Expand the MySQL server node and right-click the sample database and choose Connect.

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.

services window2

Figure 12. Sample database node in in the Services window

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.

Creating the Persistence Unit

To 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.

  1. Right-click the project node in the Projects window and choose Properties.

  2. In the Sources category of the Properties window, select JDK 6 as the Source/Binary Format. Click OK.

  3. Choose New File (Ctrl-N; ⌘-N on Mac) to open the New File wizard.

  4. Select Persistence Unit from the Persistence category. Click Next.

  5. Keep the default name for the persistence unit suggested by the wizard.

  6. Choose EclipseLink in the Persistence Provider drop-down list.

  7. Choose New Data Source in the Data Source dropdown list.

  8. Type jdbc/mysql-sample for the JNDI name in the New Data Source dialog box.

  9. Choose the MySQL sample database connection. Click OK to close the dialog box.

  10. Click Finish in the New Persistence Unit wizard.

new persistence eclipselink1

Figure 13. New Persistence Unit wizard

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 Classes

You will now use the Entity Classes from Database wizard to create the entity classes based on the relational database.

  1. Choose New File (Ctrl-N) to open the New File wizard.

  2. Select Entity Classes from Database from the Persistence category. Click Next.

  3. In the Entity Classes from Database wizard, select jdbc/mysql-sample from the Data Source drop-down list and supply the password, if necessary.

  4. Select the Customer table from the Available Tables and click Add. Click Next.

The wizard lists the customer table and the related tables under Selected Tables.

  1. Type ejb as the package for the generated classes. Click Finish.

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 Pages

In this exercise you will use a wizard to generate JSF pages based on the existing entity classes.

  1. Right-click the project node and choose New > Other.

  2. Select JSF Pages from Entity Classes in the JavaServer Faces category of the New File wizard. Click Next.

  3. Click Add All to create JSF pages for all the available entities. Click Next.

  4. Type web for the package for the session beans and JPA controller classes. Click Finish.

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 Project

In 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.

  1. Right-click the project node and choose Run.

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.

browser welcome

Figure 14. Welcome page in 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.

adminconsole deployments

Figure 15. Deployments table in WebLogic Server Admin Console

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.

  • If you deployed the application to WebLogic Server 10.3.4 or 10.3.5 you can see in the table that the JSF 2.0 library was also deployed to the server in addition to the WebLogicCustomer.war web application and the jdbc/mysql-sample JDBC configuration.

admin console deployments

Figure 16. Deployments table in WebLogic Server Admin Console

  • If you expand the Oracle WebLogic Server instance in the Services window, you can view the applications and resources that are deployed to the server. You can see that the JDBC resources were created on the server and that the JSF libraries were installed.

weblogic services window2

Figure 17. WebLogic Server applications and resources in the Services window

How to Change Jdk Version in Weblogic 10.3 6

Source: http://netbeans.apache.org/kb/docs/web/jsf-jpa-weblogic.html

0 Response to "How to Change Jdk Version in Weblogic 10.3 6"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel