Sun Java Solaris Communities My SDN Account Join SDN
 
Article

Deploying J2EE Applications or Modules to Sun Java System Application Server Platform Edition 8

 
By Vijay Ramachandran and Marina Sum, June 23, 2004  
Sun Java System Application Server, Platform Edition 8 (Application Server PE 8) is the first production-quality application server that's compatible with Java 2 Platform, Enterprise Edition (J2EE platform) 1.4. Free for development, deployment, and redistribution, Application Server PE 8 offers J2EE 1.4 API updates along with fully integrated and enhanced tools and technologies.

This article describes the ways in which you can deploy J2EE applications or modules to Application Server PE 8.
Contents
 
Overview of Deployment
Method 1: Command Line
Method 2: Administration Console
Method 3: Application Deployment Tool
Method 4: Automatic Deployment
Method 5: Directory-Based Deployment
Dynamic Reloading
References
Acknowledgment
About the Authors
 
Overview of Deployment

A typical development process for J2EE applications contains two steps:

  1. Create JavaServer Pages (JSP) components that handle the presentation logic of the application and build servlet or Enterprise JavaBeans (EJB) components to manage the application's business logic.

  2. Assemble those components into a single unit that can be deployed to a J2EE platform-compliant application server, such as Application Server PE 8.

    The deployable unit can be either of the following:

    • J2EE module -- A collection of J2EE components that reside in the same container. The modules can be a Web archive (WAR), an EJB Java archive (JAR), a resource adapter archive (RAR), or an application client JAR.

    • J2EE application -- A collection of J2EE modules along with application deployment descriptors in the form of EAR files.

This article shows you the five ways in which to deploy J2EE applications or modules to Application Server PE 8, some of which help reduce the length of the develop-deploy-debug cycle. However, this article does not address the structure of the deployable units. For details on that structure, see The J2EE 1.4 Tutorial and Chapter 3, "Assembling and Deploying J2EE Applications" in the Sun Java System Application Server Platform Edition 8 Developer's Guide.

 
Method 1: Command Line

Application Server PE 8 includes a command-line interface (CLI), asadmin (short for Application Server Administration), which, in addition to performing administration tasks on Application Server PE 8, (such as creating and managing resources), can also deploy units. asadmin resides in the Application_Server_install_dir/bin directory.

Before deploying with asadmin, ensure that your J2EE module or application is packaged according to the specification. This method is useful for situations in which you desire to deploy from within scripts or when your applications are packaged and deployment-ready.

For example, to deploy a WAR called hello.war and an EAR called test.ear, type:

% asadmin deploy --user admin_user --password admin_password hello.war
% asadmin deploy --user admin_user --password admin_password test.war

To undeploy, execute the asadmin undeploy command.


Note - If you elected during installation to have Application Server PE 8 remember the administrator password, you need not add the user and password options when you run asadmin.


asadmin offers other options, for example, compiling all JSP pages during deployment and keeping the application in a disabled state after deployment. Here is the syntax:

asadmin deploy --user admin_user [--password admin_password]
	[--host localhost] [--port 4848] [--passwordfile filename]
	[--secure|-s] [--virtualservers virtual_servers]
	[--type application|ejb|web|connector]
	[--contextroot context_root] [--force=true]
	[--precompilejsp=false]
	[--verify=false] [--name component_name] [--upload=true]
	[--retrieve local_dirpath] [--instance instance_name] filepath

For details on the options, see the deploy(1) man page or command-line help.

 
Method 2: Administration Console

You can also deploy applications or modules from the Administration Console of Application Server PE 8.


Reminder - For this deployment method to work, your application or module must be completely and properly packaged.


Follow these steps:

  1. Go to the Administration Console at http://hostname:portnumber/admin.
    For example, if your browser is running on the same machine as Application Server PE 8 and you chose, during installation, to use the default administration port 4848, then go to http://localhost:4848/admin.


  2. Type the administrator's user name and password and click Log In.
    The page for Application Server PE 8 is displayed.


  3. Select the appropriate type of application under Applications.
    For example, for a WAR module, select Web Applications. For an EAR file, select Enterprise Applications.


  4. Click the Deploy button on the right panel.

  5. Select the deployable unit and click Next.

  6. Select the appropriate choices.
    For example, to have all JSP pages compiled at deployment, select the Precompile: checkbox.


  7. Click OK.
    You will have deployed your module or application on Application Server PE 8.

To undeploy, select the application or module and click Undeploy in step 3.

For details on how to use the Administration Console, see "Admin Console Tasks for Deploying Applications" in the Sun Java System Application Server Platform Edition 8 Administration Guide.

 
Method 3: Application Deployment Tool

Application Server PE 8 contains Application Deployment Tool (deploytool), a handy GUI for assembling and deploying packaged applications or modules. Like asadmin, deploytool also resides in the Application_Server_install_dir/bin directory.

To deploy, first load the application or module into deploytool and then choose Deploy from the Tools menu.

To undeploy, select the deployed application or module and then click Undeploy.

For details on how to assemble and deploy J2EE modules or applications, see The J2EE 1.4 Tutorial.

 
Method 4: Automatic Deployment

Automatic deployment is the quickest way to deploy applications or modules. To use this method, simply copy the deployable unit into a directory called autodeploy, which resides under this directory by default:

Application_Server_install_dir/domains/domain1/

Also by default, Application Server PE 8 polls the autodeploy directory every two seconds and deploys any new, deployable units.

To change those default values:

  1. Log in to the Administration Console.

  2. Click Applications.
    The Application Configurations page is displayed.


  3. Revise the values in the Auto Deploy Poll Interval and Auto Deploy Directory fields and then click Save.

  4. Shut down and restart the domain.

To undeploy a unit, simply delete it from the autodeploy directory.

 
Method 5: Directory-Based Deployment

Often, the environment for your application or module resides in the same directory structure as required and you would like to deploy the structure rather than archiving it into a WAR, JAR, or EAR and then deploying the archive with one of the preceding methods. Application Server PE 8 supports directory-based deployment with the CLI asadmin deploydir--an ideal way to accomplish incremental deployment.

Here is an example. You are deploying an application called hello (hello.ear) that contains an EJB module (hello.jar). With directory-based deployment, the build scripts for your application create the source and deployment descriptors such that the built files always follow the directory structure. FIGURE 1 illustrates the directory structure.

 
FIGURE 1: Example of Directory-Based Deployment
FIGURE 1: Example of Directory-Based Deployment

Assuming that the directory hello resides in /home/user, type the following command line (all on one line) to deploy the application:

% asadmin deploydir --user admin --password admin_password /home/user/hello

Here is the complete syntax:

asadmin deploydir --user admin_user [--password admin_password]
	[--host localhost] [--port 4848] [--secure | -s]
	[--passwordfile filename] [--terse=false] [--echo=false]
	[--interactive=true] [--virtualservers virtual_servers]
	[--contextroot context_root] [--force=true] [--verify=false]
	[--precompilejsp=false][--name component_name]
	[--uniquetablenames=true|false]
	[--dbvendorname dbvendorname]
	[--createtables=false | --dropandcreatetables=false]
	[--generatermistubs=false] [--availabilityenabled=false]
	[--target target] dirpath

Dynamic Reloading

Frequently, while developing a J2EE application or module, you would like to slightly revise a JSP page, servlet, or an EJB class and quickly test the changes before moving on to the next step. Testing minor changes can become a burdensome task if, for each of them, you must assemble and package the application or module into the appropriate WAR, JAR, or EAR and deploy that archive.

To ease and speed up those testing tasks, Application Server PE 8 offers dynamic reloading, with which you deploy your application or module once only. From then on, to test minor changes, you need not repackage and redeploy the entire application or module. Instead, simply replace the latest JSP page, servlet, or EJB class; Application Server PE 8 automatically reloads the most current files.

Remember: You must revise the files where they are deployed. For example, after you've deployed an EAR, that application is at Application_Server_install_dir/domains/domain1/applications/j2ee-apps/application_name. You must input the changes into the files that reside in this location.

Once the changes are in place, you can enable the Application Server PE 8 to determine which files contain updates. Create a file called .reload according to these rules:

  • If the revised files belong to an application, create the .reload file under Application_Server_install_dir/domains/domain1/applications/j2ee-apps/application_name.

  • If the revised files belong to a module, create the .reload file under Application_Server_install_dir/domains/domain1/applications/j2ee-modules/ module_name.

 

Note - If the .reload file already exists, just update its timestamp to reflect the current time. This way, Application Server PE 8 can determine whether the files of an application or module have changed.


By default, dynamic reloading is enabled in Application Server PE 8, and if .reload exists, Application Server PE 8 checks the file's timestamp every 20 seconds. To change those default values:

  1. Log in to the Administration Console.

  2. Click Applications.
    The Application Configurations page is displayed.


  3. Revise the values in the Reload checkbox and Reload Poll Interval fields as you desire. Click Save.

  4. Shut down and restart the domain.

 
References
 
Acknowledgment

Special thanks to Qingqing Ouyang and Hong Zhang at Sun, whose comments greatly enhanced this article.

 
About the Authors

Vijay Ramachandran, a member of the Sun Java System Application Server Development Team, has been with Sun for over six years. Previously, Vijay served as technical lead for the Java BluePrints team. He's also the coauthor of Designing Enterprise Applications with the J2EE Platform, 2nd Edition, and a forthcoming book, Designing Web Services with the J2EE Platform.

Marina Sum is a staff writer for Sun Developer Network. She has been writing for Sun for 15 years, mostly in the technical arena.

 
Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.