You can manage J2EE RI applications using any of the following interfaces:
Using deploytool you can obtain a list of deployed objects by selecting the localhost:4848 entry under Servers in the left pane and a list of deployed components will be displayed, as shown in Figure 4.12.
You can start, stop and undeploy an object using the appropriate buttons on this dialog.
Should you need to retrieve a client JAR file from a deployed application you can do this by selecting your application, clicking on the Client Jar... button and specifying a directory location on the popup dialogue window.
If you prefer to work from the command line, then you can use the asadmin utility. To deploy an application you use the asadmin deploy command. To deploy the example EAR file you have been viewing use the command
asadmin deploy --user admin --force j2ee-ri/agency.ear
You need to specify the name of your administrative user and the EAR filename; the --force option forces a redeployment if the application has already been deployed. You will be prompted for the administrative password unless you have stored this password in a configuration file, or as an environment variable, as described on Day 2 under the installation instructions for the J2EE SDK.
If you want to return the client JAR file when deploying an application use a command such as:
asadmin deploy --user admin --force --retrieve j2ee-ri j2ee-ri/agency.ear
The --retrieve option requires the name of the directory for the client JAR file; the client JAR filename is derived from the application name as described previously.
You can retrieve the client JAR file for a previously deployed application using the get-client-stubs command to asadmin as follows:
asadmin get-client-stubs --user admin --appname agency j2ee-ri
This command requires the application name (--appname option) and the target directory for the client JAR file.
As discussed on Day 2 asadmin will provide useful help messages when an invalid command is entered. And, you can always use the --help option to get more information. For example:
Finally, you can administer deployed applications using the J2EE RI Admin Console at http://localhost:4848/asadmin/. Select the Applications, Enterprise Applications option in the left pane to deploy and undeploy applications as shown in Figure 4.13.
You can only stop, start, deploy and undeploy applications using the Admin Console interface; you cannot return client JAR files.
Case Study asant Build Files
As an alternative to using deploytool to build and deploy J2EE components, you can use Apache Ant (sometimes called Jakarta Ant) to assemble the EAR or WAR files from the constituent components. Ant is a Java-based, open source, automated build tool that is quickly becoming the de facto standard build tool for Java programmers. A version of Apache Ant, called asant, is included with the J2EE SDK and example asant build files are supplied with the J2EE 1.4 Tutorial examples. A discussion on writing the Ant build files required to assemble a J2EE archive is outside the scope of this book, but the online Ant documentation at http://ant.apache.org/manual/index.html gives a good introduction to writing build files. Alternatively you could check out the book Extreme Programming with Ant from SAMS Publishing.
On the accompanying Web site, asant build files have been provided to compile and package the EAR and WAR files used throughout this book. As described in Day 2, each working directory contains a build.xml file that defines the asant build targets appropriate for the directory.
The build.xml file in the Day04/exercise directory will build, deploy, and run the simple client example. In order to help you use asant with the case study, each build.xml file contains a help build target that will tell you which targets you can use for each directory, this is also the default asant target. Run the following command from the Day04/exercise directory to see what targets are available:asant
To remove all the temporary files and then compile and build the case study from scratch, use the command
asant clean build
The generated agency.ear file is stored in the build subdirectory and is kept separate from the supplied agency.ear file in the j2ee-ri directory. The various deployment descriptors used to build the EAR file are kept in the dd/agency subdirectory.
You can verify the built application using the command
The verification results from this command are stored in the file build/agency.ear.txt.
To deploy the case study from the build directory, use the command
This will return the client JAR as build/agencyClient.jar. To run the simple client example, use the command
You should see the following output:
To undeploy the agency example use
If you want to use deploytool to build the EAR file but work at the command line to verify, deploy and run the examples, then you can use the following commands.
Verify the deploytool maintained agency.ear file in the j2ee-ri sub-directory with
Deploy and return the j2ee-ri/agencyClient.jar file withasant deploy-j2ee-ri
Run the application client (in the j2ee-ri sub-directory) using
To undeploy the agency example you still use
blog comments powered by Disqus