站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > The J2EE 1.4 Tutorial

Building, Packaging, Deploying, and Running the Application - The J2EE 1.4 Tutorial

Building, Packaging, Deploying, and Running the Application

The source code for the Coffee Break application is located in the directory <INSTALL>/j2eetutorial14/examples/cb/. Within the cb directory are subdirectories for each web application--saaj, jaxrpc, server, and server-jsf--and a directory, common, for classes shared by the web applications. Each subdirectory contains a build.xml and build.properties file. The web application subdirectories in turn contain a src subdirectory for Java classes and a web subdirectory for web resources.

Setting the Port

The JAX-RPC and SAAJ services in the Coffee Break application run at the port that you specified when you installed the Application Server. The tutorial examples assume that the Application Server runs on the default port, 8080. If you have changed the port, you must update the port number in the following files before building and running the examples:

  • <INSTALL>/j2eetutorial14/examples/cb/common/src/com/sun/cb/CoffeeBreak.properties. Update the port in the following URLs:
    • endpoint.url=http://localhost:8080/jaxrpc-coffee-supplier/jaxrpc
    • saaj.url=http://localhost:8080/saaj-coffee-supplier
  • <INSTALL>/j2eetutorial14/examples/cb/jaxrpc/config-wsdl.xml

Setting the Registry Properties

The Coffee Break servers use a registry to obtain information about the JAX-RPC service endpoint. Since the Application Server does not include a registry, you must use an external registry. See Preliminaries: Getting Access to a Registry for information on registering with a public UDDI registry. If you previously ran the JAXR examples, you can use the same registry.

Before you build the Coffee Break application, you need to set properties in much the same way you did with the JAXR examples:

  1. Open the file <INSTALL>/j2eetutorial14/examples/cb/common/src/com/sun/cb/CoffeeBreak.properties in an editor.
  2. Edit the following lines to specify the registry you wish to access. For the query.url and the publish.url assignments, comment out all but the registry you wish to access. The default is the IBM registry.
  3. ## IBM:
    query.url=http://uddi.ibm.com/testregistry/inquiryapi
    publish.url=https://uddi.ibm.com/testregistry/publishapi
    ## Microsoft:
    #query.url=http://test.uddi.microsoft.com/inquire
    #publish.url=https://test.uddi.microsoft.com/publish

  4. Edit the following lines to specify the user name and password you obtained when you registered with the registry.
  5. ## Specify user name and password
    registry.username=
    registry.password=

  6. Edit the following lines, which contain empty strings for the proxy hosts, to specify your own proxy settings. The proxy host is the system on your network through which you access the Internet; you usually specify it in your Internet browser settings.
  7. ## HTTP and HTTPS proxy host and port
    http.proxyHost=
    http.proxyPort=8080
    https.proxyHost=
    https.proxyPort=8080

    The proxy ports have the value 8080, which is the usual one; change this string if your proxy uses a different port.

    Your entries usually follow this pattern:

    http.proxyHost=proxyhost.mydomain
    http.proxyPort=8080
    https.proxyHost=proxyhost.mydomain
    https.proxyPort=8080

Using the Provided WARs

The instructions that follow for packaging and deploying the Coffee Break web applications assume that you are familiar with the deploytool procedures for packaging web services and presentation-oriented web applications described in previous chapters of the tutorial. If after following these procedures you have trouble deploying or running the application, you can compare your WAR files to the WAR files provided in <INSTALL>/j2eetutorial14/examples/cb/provided-wars/. You cannot deploy the WAR files in this directory, because they use the unedited version of the <INSTALL>/j2eetutorial14/examples/cb/common/src/com/sun/cb/CoffeeBreak.properties file.

Building the Common Classes

The Coffee Break applications share a number of common utility classes. To build the common classes and copy the CoffeeBreak.properties file into the build directory, do the following:

  1. In a terminal window, go to <INSTALL>/j2eetutorial14/examples/cb/common/.
  2. Run asant build.

Building, Packaging, and Deploying the JAX-RPC Service

To build the JAX-RPC service and client library and to package and deploy the JAX-RPC service, follow these steps:

  1. In a terminal window, go to <INSTALL>/j2eetutorial14/examples/cb/jaxrpc/.
  2. Run asant build-registry and asant build-service. These tasks create the JAR file containing the JAXR routines and run wscompile and compile the source files of the JAX-RPC service.
  3. If you get an error, make sure that you edited the file <INSTALL>/j2eetutorial14/examples/common/build.properties as described in Building the Examples.

  4. Make sure the Application Server is running.

To package and deploy the JAX-RPC service using asant, follow these steps:

  1. Run asant create-war.
  2. If you did not do so in Chapter 10, follow the instructions in Creating JAXR Resources to create a JAXR connection factory named eis/JAXR.
  3. Run asant deploy-war.

To package and deploy the JAX-RPC service using deploytool, follow these steps:

  1. Start deploytool.
  2. Select File from the deploytool menu, then New, then Web Component. Use the New Web Component wizard to create a stand-alone web module named jaxrpc-coffee-supplier in <INSTALL>/j2eetutorial14/examples/cb/jaxrpc/.
  3. Set the context root to /jaxrpc-coffee-supplier.
  4. Add the content to the service.
    1. Add the com package, Supplier.wsdl, and mapping.xml under <INSTALL>/j2eetutorial14/examples/cb/jaxrpc/build/server/ to the module.
    2. Navigate to <INSTALL>/j2eetutorial14/examples/cb/jaxrpc/dist/ and add registry-org.jar.
    3. In the web module contents editor, drag the com directory (containing sun/cb/SupplierPrices.properties and sun/cb/CoffeeBreak.properties) from the context root to WEB-INF/classes/.
    4. Click Next.
  5. Specify Web Services Endpoint as the component type.
  6. In the Choose Service dialog box (Define New Service):
    1. Fromthe WSDL File drop-down list, select WEB-INF/wsdl/Supplier.wsdl.
    2. From the Mapping File drop-down list, select mapping.xml.
  7. In the Component General Properties dialog box:
    1. From the Service Endpoint Implementation drop-down list, select com.sun.cb.SupplierImpl.
    2. Click Next.
  8. In the Web Service Endpoint dialog box:
    1. From the Service Endpoint Interface drop-down list, select com.sun.cb.SupplierIF.
    2. In the Namespace combo box, type urn:Foo.
    3. In the Local Part combo box, type SupplierIFPort.
    4. Click Next, and then click Finish.
  9. Add the alias /jaxrpc to the SupplierImpl web component.
  10. Select the Endpoint tab, and then select jaxrpc from the Endpoint Address combo box in the Sun-specific Settings area.
  11. Select the jaxrpc-coffee-supplier module and add an event listener that references the listener class com.sun.cb.ContextListener.
  12. Add a resource reference of type javax.xml.registry.ConnectionFactory named eis/JAXR mapped to the JAXR connection factory eis/JAXR. Specify j2ee as the value for both the user name and the password. If you have not already created the connection factory, follow the instructions in Creating JAXR Resources.
  13. Save the module.
  14. Deploy the module.

You will find the orgkey.txt file in the <J2EE_HOME>/domains/domain1/config directory. Check the server log for errors: <J2EE_HOME>/domains/domain1/logs/server.log.

Next, build and test the client:

  1. Run asant build-client. This task creates the JAR file that contains the classes needed by JAX-RPC clients. The build-client task runs wscompile to generate the stubs and JavaBeans components.
  2. Test that the JAX-RPC service has been deployed correctly by running the test programs asant run-test-order and asant run-test-price.
  3. Here is what you should see when you run asant run-test-price:

    run-test-price:
    run-test-client:
      [java]http://localhost:8080/jaxrpc-coffee-supplier/jaxrpc
      [java] 11/11/04 12/11/04
      [java] Wake Up Call 5.50
      [java] French Roast 5.00
      [java] Kona 6.50
      [java] Mocca 4.00

Building, Packaging, and Deploying the SAAJ Service

To build the SAAJ service and client library, follow these steps:

  1. In a terminal window, go to <INSTALL>/j2eetutorial14/examples/cb/saaj/.
  2. Run asant build. This task creates the client library and compiles the server classes.
  3. Make sure the Application Server is started.

To package and deploy the SAAJ service using asant, follow these steps:

  1. Run asant create-war.
  2. Run asant deploy-war.

To package and deploy the SAAJ service using deploytool, follow these steps:

  1. Start deploytool.
  2. Create a stand-alone web module called saaj-coffee-supplier in <INSTALL>/j2eetutorial14/examples/cb/saaj/.
  3. Set the context root to /saaj-coffee-supplier.
  4. Add the com directory under <INSTALL>/j2eetutorial14/examples/cb/saaj/build/server/ to the module.
  5. Add the ConfirmationServlet web component. Choose the Servlet component type.
  6. Add the alias /orderCoffee to the ConfirmationServlet web component.
  7. Add the PriceListServlet web component to the existing saaj-coffee-supplier WAR.
  8. Add the alias /getPriceList to the PriceListServlet web component.
  9. Save the module.
  10. Deploy the module.

Test that the SAAJ service has been deployed correctly by running one or both of the test programs asant run-test-price and asant run-test-order.

Building, Packaging, and Deploying the Coffee Break Server

To build the Coffee Break server:

  1. In a terminal window, go to <INSTALL>/j2eetutorial14/examples/cb/server/.
  2. Run asant build. This task compiles the server classes and copies the classes, JSP pages, and tag libraries into the correct location for packaging.
  3. Make sure the Application Server is started.

To package and deploy the Coffee Break server using asant, follow these steps:

  1. Run asant create-war.
  2. Run asant deploy-war.

To package and deploy the Coffee Break server using deploytool, follow these steps:

  1. Start deploytool.
  2. Create a stand-alone web module called cbserver in <INSTALL>/j2eetutorial14/examples/cb/server/.
  3. Set the context root to /cbserver.
  4. Add the content to the web module.
    1. Add all the JSP pages, tutorial-template.tld, and the template and com directories under <INSTALL>/j2eetutorial14/examples/cb/server/build/ to the module.
    2. In the web module contents editor, drag the com directory (containing sun/cb/CoffeeBreak.properties) from the context root to WEB-INF/classes/.
    3. Add the JAX-RPC client library in <INSTALL>/j2eetutorial14/examples/cb/jaxrpc/dist/jaxrpc-client.jar to the module.
    4. Add the SAAJ client library in <INSTALL>/j2eetutorial14/examples/cb/saaj/dist/saaj-client.jar to the module.
  5. Create a Dispatcher web component. Choose the Servlet component type.
  6. Add the aliases /orderForm, /checkoutForm, and /checkoutAck to the Dispatcher component.
  7. Add the RetailPriceListServlet web component to the existing cbserver WAR.
  8. Add the alias /loadPriceList to the RetailPriceListServlet component.
  9. Add a resource reference of type javax.xml.registry.ConnectionFactory named eis/JAXR mapped to the JAXR connection factory eis/JAXR, with the user name and password both j2ee.
  10. Add a JSP property group named cbserver. The property group applies to the URL pattern *.jsp. Add the include prelude /template/prelude.jspf.
  11. Add a context parameter named javax.servlet.jsp.jstl.fmt.localizationContext and value com.sun.cb.messages.CBMessages.
  12. Specify a security constraint for the cbserver WAR.
    1. Select Basic as the User Authentication Method.
    2. Click Settings and enter file in the Realm Name field. Click OK.
    3. Add a security constraint and a web resource collection. Use the default names provided by deploytool.
    4. Add the URL /loadPriceList to the web resource collection.
    5. Select the GET HTTP method.
    6. Add the security role admin.
  13. Save the module.
  14. Deploy the module.

Building, Packaging, and Deploying the JavaServer Faces Technology Coffee Break Server

To build the JavaServer Faces technology version of the Coffee Break server, follow these steps:

  1. In a terminal window, go to <INSTALL>/j2eetutorial14/examples/cb/server-jsf/.
  2. Run asant build. This task compiles the server classes and copies the classes, JSP pages, tag libraries, and other necessary files into the correct location for packaging.
  3. Make sure the Application Server is started.

To package and deploy the JavaServer Faces technology version of the Coffee Break server using asant, follow these steps:

  1. Run asant create-war.
  2. Run asant deploy-war.

To package and deploy the JavaServer Faces technology version of the Coffee Break server using deploytool, follow these steps:

  1. Start deploytool.
  2. Create a stand-alone web module called cbserver-jsf in <INSTALL>/j2eetutorial14/examples/cb/server-jsf/.
  3. Set the context root to /cbserver-jsf.
  4. Add the content to the web module.
    1. Add all the JSP pages, coffeebreak.css, faces-config.xml, index.html, and the template and com directories under <INSTALL>/j2eetutorial14/examples/cb/server-jsf/build/ to the module.
    2. In the web module contents editor, drag the com directory (containing sun/cb/CoffeeBreak.properties) from the context root to WEB-INF/classes.
    3. Drag faces-config.xml to the root of the WEB-INF directory.
    4. Add the JAX-RPC client library in <INSTALL>/j2eetutorial14/examples/cb/jaxrpc/dist/jaxrpc-client.jar to the module.
    5. Add the SAAJ client library in <INSTALL>/j2eetutorial14/examples/cb/saaj/dist/saaj-client.jar to the module.
    6. Add the file <J2EE_HOME>lib/jsf-api.jar to the module.
  5. Create a FacesServlet web component. Choose the Servlet component type.
    1. In the Startup Load Sequence Position field on the Component General Properties dialog, enter 1.
  6. Add the aliases /faces/* and *.jsf to the FacesServlet component.
  7. Add a resource reference of type javax.xml.registry.ConnectionFactory named eis/JAXR mapped to the JAXR connection factory eis/JAXR, with the user name and password both j2ee.
  8. Add a JSP property group named cbserver-jsf. The property group applies to the URL pattern *.jsp. Add the include prelude /template/prelude.jspf.
  9. Save the module.
  10. Deploy the module.

Running the Coffee Break Client

After you have installed all the web applications, check that all the applications are running in deploytool or the Admin Console. You should see cbserver (or cbserver-jsf), jaxrpc-coffee-supplier, and saaj-coffee-supplier in the list of applications.

If you have installed the non-GUI framework version of the Coffee Break server, you can run the Coffee Break client by opening the Coffee Break server URL in a web browser:

http://localhost:8080/cbserver/orderForm 

If you have installed the JavaServer Faces technology version of the Coffee Break server, you can run the JavaServer Faces version of the Coffee Break client by opening this URL in a web browser:

http://localhost:8080/cbserver-jsf/faces/orderForm.jsp 

You should see a page something like the one shown in Figure 35-2.

Coffee Break Order Form

Figure 35-2 Order Form

After you have gone through the application screens, you will get an order confirmation that looks like the one shown in Figure 35-3.

Coffee Break Order Confirmation

Figure 35-3 Order Confirmation

Removing the Coffee Break Application

To remove the Coffee Break application, perform the following steps:

  1. Undeploy the JAX-RPC and SAAJ services and the Coffee Break server using deploytool or the Admin Console or by running asant undeploy-war. When you undeploy the JAX-RPC service, the JAXRPCCoffeeSupplier organization is deleted from the registry.
  2. Stop the Application Server.

If you want to remove the build and dist directories, run asant clean in each directory, including <INSTALL>/j2eetutorial14/examples/cb/common/.