| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| |
| <html> |
| <head> |
| <meta name="author" content="troy.giunipero@sun.com"> |
| <meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
| <meta name="description" content="This document provides basic setup instructions necessary to configuring your development environment for use with the Pet Catalog sample application."> |
| |
| <meta name="keywords" content="NetBeans, IDE, integrated development environment, |
| Java, Java EE, open source, web technology, JavaServer Faces, JSF 2.0"> |
| |
| <link rel="stylesheet" type="text/css" href="../../netbeans.css"> |
| |
| <title>Pet Catalog - Java EE 6 Sample Application - Setup Instructions</title> |
| </head> |
| |
| <body> |
| |
| <!-- Copyright (c) 2009, 2010, 2011, Oracle and/or its affiliates. All rights reserved. --> |
| |
| <h1>Pet Catalog - Java EE 6 Sample Application</h1> |
| |
| <p>The Pet Catalog application is a Java EE 6 sample that demonstrates usage of |
| JavaServer Faces 2.0 and the Java Persistence API. Setup instructions here |
| assume that you are using the following software components:</p> |
| |
| <ul style="margin: 5px 0 0 -1em"> |
| <li><a href="http://glassfish.dev.java.net/public/downloadsindex.html">GlassFish server</a> Open Source Edition 3.x</li> |
| <li><a href="http://dev.mysql.com/downloads/mysql/">MySQL database server</a> (version 5.1)</li> |
| </ul> |
| |
| <p>For more information on the Pet Catalog Sample Application, see: <a href="pet-catalog.html">https://netbeans.org/kb/samples/pet-catalog.html</a>.</p> |
| |
| <h2>Setup Instructions</h2> |
| |
| <ol> |
| <li><a href="#database">Setting up the Database</a></li> |
| <li><a href="#connPool">Configuring a Connection Pool and JDBC Resource on GlassFish</a></li> |
| <li><a href="#runSample">Running the Sample Application</a></li> |
| </ol> |
| |
| <div class="indent"> |
| <h3 id="database">Setting up the Database</h3> |
| |
| <p>Setup instructions use '<code>root</code>' / '<code>nbuser</code>' as the user |
| account / password combination for access to the MySQL server. <strong>Do not</strong> |
| use an empty database password.</p> |
| |
| <div class="indent"> |
| <h4>Change the Root Account Password to '<code>nbuser</code>'</h4> |
| |
| <ol> |
| <li>Open a command-line prompt and navigate to the <code>bin</code> directory |
| within your MySQL installation. |
| |
| <pre class="examplecode">shell> cd <em><install-dir></em>/bin</pre> |
| |
| (Where <code><em><install-dir></em></code> is the path to your MySQL |
| installation directory.)<br><br></li> |
| |
| <li>Type in the following: |
| |
| <pre class="examplecode"> |
| shell> mysql -u root |
| mysql> UPDATE mysql.user SET Password = PASSWORD('nbuser') WHERE User = 'root'; |
| mysql> FLUSH PRIVILEGES;</pre> |
| |
| For more information, see the official MySQL Reference Manual: |
| <a href="http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html">Securing |
| the Initial MySQL Accounts</a>. |
| </li> |
| </ol> |
| |
| |
| <h4>Register the Server in the IDE</h4> |
| |
| <ol> |
| <li>In the Services window (Ctrl-5; ⌘-5 on Mac), right-click the Databases |
| node and choose Register MySQL Server. |
| |
| <br> |
| <img src="../../images_www/sample-catalog/pet-catalog-setup/register-mysql-server.png" |
| class="margin-around b-all" alt="Services window - right-click options on Databases node" |
| title="Register a MySQL server in the IDE's Services window"></li> |
| |
| <li>In the MySQL Server Properties dialog, under the Basic Properties tab, you |
| can see the default settings for the MySQL server installation. These are: |
| |
| <ul style="margin: 5px 0 0 -1em"> |
| <li><strong>Server Host Name:</strong> <code>localhost</code></li> |
| <li><strong>Server Port Number:</strong> <code>3306</code></li> |
| <li><strong>Administrator User Name:</strong> <code>root</code></li> |
| <li><strong>Administrator Password:</strong> <code>nbuser</code></li> |
| </ul></li> |
| |
| <li>Select the Save Password option. |
| |
| <br> |
| <img src="../../images_www/sample-catalog/pet-catalog-setup/mysql-server-properties.png" |
| class="margin-around b-all" alt="MySQL Server Properties dialog" |
| title="Specify MySQL server settings"></li> |
| |
| <li>Click OK. The IDE connects to your MySQL database server, and lists database |
| instances that are maintained by the server.</li> |
| </ol> |
| |
| |
| <h4>Create a Database Instance</h4> |
| |
| <ol> |
| <li>Right-click the MySQL Server node and choose Create Database.</li> |
| |
| <li>In the dialog that displays, type in <code>petcatalog</code>. Select the |
| 'Grant Full Access to' option, then select <code>root@localhost</code> from |
| the drop-down field. |
| |
| <br> |
| <img src="../../images_www/sample-catalog/pet-catalog-setup/create-mysql-db-dialog.png" |
| class="margin-around b-all" alt="Create MySQL Database dialog" |
| title="Right-click the server node and choose Create Database to create a new database instance"></li> |
| |
| <li>Click OK. When you do so, an empty database named <code>petcatalog</code> is |
| created, and a connection to the database is automatically established. |
| Connections are displayed in the Services window using a connection node ( |
| <img src="../../images_www/sample-catalog/pet-catalog-setup/db-connection-node.png" alt="Database connection node"> ).</li> |
| </ol> |
| |
| |
| <h4>Create database tables and populate them with sample data</h4> |
| |
| <ol> |
| <li>In the Projects window, expand the Server Resources node and double-click |
| <code>catalog.sql</code> to open it in the IDE's editor.</li> |
| |
| <li>In the Connection drop-down above the editor, select the |
| <code>jdbc:mysql://localhost:3306/petcatalog</code> connection that you |
| created in the previous step.</li> |
| |
| <li>Click the Run SQL ( <img src="../../images_www/sample-catalog/pet-catalog-setup/run-sql-btn.png" alt="Run SQL button"> |
| ) button in the editor's toolbar. The script runs on your MySQL server.</li> |
| </ol> |
| </div> |
| |
| |
| <h3 id="connPool">Configuring a Connection Pool and JDBC Resource on GlassFish</h3> |
| |
| <p>The <code>sun-resources.xml</code> file, included in the sample application, is a |
| GlassFish-specific deployment descriptor.<a href="#note"><strong>*</strong></a> If |
| you open the file in the editor (from the Projects window, Server Resources > |
| <code>sun-resources.xml</code>), you can see that the file instructs the GlassFish |
| server to create a connection pool named <code>petCatalogPool</code> using the |
| '<code>root</code>' / '<code>nbuser</code>' combination and <code>jdbc:mysql://localhost:3306/petcatalog</code> |
| connection you configured in the previous steps:</p> |
| |
| <div class="indent"> |
| <pre class="examplecode"> |
| <jdbc-connection-pool allow-non-component-callers="false" |
| associate-with-thread="false" |
| connection-creation-retry-attempts="0" |
| connection-creation-retry-interval-in-seconds="10" |
| connection-leak-reclaim="false" |
| connection-leak-timeout-in-seconds="0" |
| connection-validation-method="auto-commit" |
| datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" |
| fail-all-connections="false" |
| idle-timeout-in-seconds="300" |
| is-connection-validation-required="false" |
| is-isolation-level-guaranteed="true" |
| lazy-connection-association="false" |
| lazy-connection-enlistment="false" |
| match-connections="false" |
| max-connection-usage-count="0" |
| max-pool-size="32" |
| max-wait-time-in-millis="60000" |
| name="petCatalogPool" |
| non-transactional-connections="false" |
| pool-resize-quantity="2" |
| res-type="javax.sql.ConnectionPoolDataSource" |
| statement-timeout-in-seconds="-1" |
| steady-pool-size="8" |
| validate-atmost-once-period-in-seconds="0" |
| wrap-jdbc-objects="false"> |
| |
| <property name="URL" value="jdbc:mysql://localhost:3306/petcatalog"/> |
| <property name="User" value="root"/> |
| <property name="Password" value="nbuser"/> |
| </jdbc-connection-pool></pre> |
| </div> |
| |
| <p>The <code>sun-resources.xml</code> file also instructs the GlassFish server |
| to configure a data source that uses the <code>petCatalogPool</code> connection |
| pool and sets its JNDI name to '<code>jdbc/petcatalog</code>':</p> |
| |
| <div class="indent"> |
| <pre class="examplecode"> |
| <jdbc-resource enabled="true" |
| jndi-name="jdbc/petcatalog" |
| object-type="user" |
| pool-name="petCatalogPool"> |
| </jdbc-resource></pre> |
| |
| <br> |
| <p id="note"><strong>*</strong> The <code>sun-resources.xml</code> file is <em>not</em> included |
| in the sample application bundled with IDE versions 6.8 and 6.9. To create the file, |
| perform the following steps.</p> |
| |
| <ol> |
| <li>Open the Files window (Ctrl-2; ⌘-2 on Mac).</li> |
| |
| <li>Create a new folder in the <code>PetCatalog</code> project named <code>setup</code>. |
| To do so, right-click the project node and choose New > Folder. (If Folder is |
| not displayed, choose Other. Select the Other category, then select the Folder file |
| type. Click Next.)</li> |
| |
| <li>Name the folder <code>setup</code>, then click Finish.</li> |
| |
| <li>Save <a href="../../images_www/sample-catalog/pet-catalog-setup/sun-resources.xml"><code>sun-resources.xml</code></a> |
| to your computer.</li> |
| |
| <li>Copy (Ctrl-C; ⌘-C on Mac) the <code>sun-resources.xml</code> file from the |
| location on your computer, then paste (Ctrl-V; ⌘-V on Mac) it into the <code>setup</code> |
| folder.</li> |
| |
| <li>Switch to the Projects window (Ctrl-1; ⌘-1 on Mac) and note that the |
| <code>sun-resources.xml</code> file is displayed in the Server Resources node |
| within the project.</li> |
| </ol> |
| </div> |
| |
| |
| <h3 id="runSample">Running the Sample Application</h3> |
| |
| <ol> |
| <li>In the Services window, expand the Servers > GlassFish Server 3 node and |
| choose Properties. In the Servers window that displays, make sure the 'Enable |
| JDBC Driver Deployment' option is selected. This option will ensure that the |
| <a href="http://www.mysql.com/downloads/connector/j/">Connector/J</a> driver |
| is deployed to GlassFish when your project is deployed. (If the server is already |
| running, you'll need to restart the server.)</li> |
| |
| <li>In the Projects window, right-click the <code>PetCatalog</code> project node |
| and choose Run. The project is compiled, packaged and deployed to GlassFish. |
| The deployed application then opens in your default browser. |
| |
| <br> |
| <img src="../../images_www/sample-catalog/pet-catalog-setup/pet-catalog.png" |
| class="margin-around b-all" alt="Pet Catalog application displayed in browser " |
| title="Run the application by right-clicking the PetCatalog project node and choosing Run"> |
| </li> |
| </ol> |
| </div> |
| </body> |
| </html> |