This section describes how to build, package, deploy, and run the order application. To do this, you will create the database tables in the Java DB server, then build, deploy, and run the example.
To create the database tables in Java DB, the database server included with Application Server, you need to create the database connection and execute the SQL commands in tut-install/examples/common/sql/javadb/tutorial.sql.
To create the database connection do the following:
Click the Services tab.
Right-click the Databases node and select New Connection to open the New Connection dialog.
Under Name, select Java DB (Network).
Set Database URL to the following:
jdbc:derby://localhost:1527/sun-appserv-samples |
Set User Name to APP.
Set Password to APP.
Select the Remember Password during this Session box.
Click OK.
To create the tutorial tables, do the following:
Select File->Open File.
Navigate to tut-install/examples/common/sql/javadb/ and open tutorial.sql.
In the editor pane, select the connection URL to Java DB:
jdbc:derby://localhost:1527/sun-appserv-samples |
Click the Run SQL button at the top of the editor pane.
You will see the output from the SQL commands in the Output tab.
To delete the tutorial tables, do the following:
Select File->Open File.
Navigate to tut-install/examples/common/sql/javadb/ and open delete.sql.
In the editor pane, select the connection URL to Java DB:
jdbc:derby://localhost:1527/sun-appserv-samples |
Click the Run SQL button at the top of the editor pane.
You will see the output from the SQL commands in the Output tab.
The database tables are automatically created by the create-tables task, which is called before you deploy the application with the ant deploy task. To manually create the tables, do the following:
In a terminal window, navigate to tut-install/javaeetutorial5/examples/ejb/order/.
Type the following command:
ant create-tables |
The first time the create-tables task is run, you will see error messages when the task attempts to remove tables that don’t exist. Ignore these error messages. Subsequent calls to create-tables will run with no errors and will reset the database tables.
Follow these instructions to build, package, deploy, and run the order example to your Application Server instance using NetBeans IDE.
In NetBeans IDE, select File->Open Project.
In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/ejb/.
Select the order folder.
Select the Open as Main Project and Open Required Projects check boxes.
Click Open Project.
In the Projects tab, right-click the order project and select Run.
You will see the following output from the application client in the Output tab:
... Cost of Bill of Material for PN SDFG-ERTY-BN Rev: 7: $241.86 Cost of Order 1111: $664.68 Cost of Order 4312: $2,011.44 Adding 5% discount Cost of Order 1111: $627.75 Cost of Order 4312: $1,910.87 Removing 7% discount Cost of Order 1111: $679.45 Cost of Order 4312: $2,011.44 Average price of all parts: $117.55 Total price of parts for Vendor 100: $501.06 Ordered list of vendors for order 1111 200 Gadget, Inc. Mrs. Smith 100 WidgetCorp Mr. Jones Counting all line items Found 6 line items Removing Order 4312 Counting all line items Found 3 line items Found 1 out of 2 vendors with ’I’ in the name: Gadget, Inc. run-order-app-client: run-ant: run: BUILD SUCCESSFUL (total time: 22 seconds) |
To build the application components of order, enter the following command:
ant |
This runs the default task, which compiles the source files and packages the application into an EAR file located at tut-install/examples/ejb/order/dist/order.ear.
To deploy the EAR, make sure the Application Server is started, then enter the following command:
ant deploy |
After order.ear is deployed, a client JAR, orderClient.jar, is retrieved. This contains the application client.
To run the application client, enter the following command:
ant run |
You will see the following output:
... run: [echo] Running appclient for Order. appclient-command-common: [exec] Cost of Bill of Material for PN SDFG-ERTY-BN Rev: 7: $241.86 [exec] Cost of Order 1111: $664.68 [exec] Cost of Order 4312: $2,011.44 [exec] Adding 5% discount [exec] Cost of Order 1111: $627.75 [exec] Cost of Order 4312: $1,910.87 [exec] Removing 7% discount [exec] Cost of Order 1111: $679.45 [exec] Cost of Order 4312: $2,011.44 [exec] Average price of all parts: $117.55 [exec] Total price of parts for Vendor 100: $501.06 [exec] Ordered list of vendors for order 1111 [exec] 200 Gadget, Inc. Mrs. Smith [exec] 100 WidgetCorp Mr. Jones [exec] Counting all line items [exec] Found 6 line items [exec] Removing Order 4312 [exec] Counting all line items [exec] Found 3 line items [exec] Found 1 out of 2 vendors with ’I’ in the name: [exec] Gadget, Inc. BUILD SUCCESSFUL |
Before re-running the application client, you must reset the database by running the create-tables task.
As a convenience, the all task will build, package, deploy, and run the application. To do this, enter the following command:
ant all |
To undeploy order.ear, enter the following command:
ant undeploy |