Tuesday, 19 February 2013

how to deploy web applications (war file) in GlassFish server

Obtaining a Sample Application

The procedures in this section use the hello.war sample application.

To Obtain the Sample Application

  1. To download a copy of the hello.war sample application, go to http://www.satyamsoft.in/zip/hello.war
  2. Save the hello.war file in the directory of your choice. This directory is referred to as sample-dir.

Deploying an Application From the Command Line

You can deploy applications from the command line using the asadmin deploy command.

To Deploy the Sample Application From the Command Line

Before You Begin
The sample application must be available before you start this task. To download the sample, see Obtaining a Sample Application. At least one GlassFish Server domain must be started before you deploy the sample application.

  1. Use the asadmin deploy command.
                    The general form for the command is:
                           
                 as-install/bin/asadmin deploy war-name
          To deploy the hello.war sample, the command is : 
                 as-install/bin/asadmin deploy sample-dir/hello.war
    2.  Access the hello application by typing the following URL in your browser:  

          http://localhost:8080/hello
         
           The application's start page is displayed,
                  Hello User how are you?

To List Deployed Applications From the Command Line

  1. Use the asadmin list-applications command:          
    as-install/bin/asadmin list-applications

To Undeploy the Sample Application From the Command Line

  1. Use the asadmin undeploy command.
    The general form for the command is:       
    as-install/bin/asadmin undeploy war-name 
     
    For war-name, use the literal hello, not the full hello.war name.
    For the hello.war example, the command is:
         as-install/bin/asadmin undeploy hello
     
     

    To View Deployed Applications in the Administration Console

    1. Launch the Administration Console by typing the following 
      URL in your browser:
     
                http://localhost:4848
     
      2. Click the Applications node in the tree on the left. 
         
         Expand the node to list deployed applications. Deployed 
         applications are also listed  in the table on the Applications 
         age.
     

To Undeploy the Sample Application Using the Administration Console

  1. Launch the Administration Console by typing the following URL in your browser:
      
    http://localhost:4848
    
  2. Click the Applications node in the tree on the left.
    The Applications page is displayed.
  3. Select the check box next to the hello sample application.
  4. Remove or disable the application.
    • To remove the application, click the Undeploy button.
    • To disable the application, click the Disable button.

To Deploy the Sample Application Automatically

Before You Begin
The sample application must be available before you start this task. To download the sample, see Obtaining a Sample Application.
  1. Copy the application WAR file to the as-install/domains/domain-name/autodeploy directory.
    cp sample-dir/hello.war as-install/domains/domain-name/autodeploy
    Use copy instead of cp on Windows systems.
    GlassFish Server automatically discovers and deploys the application. The default URL for the application is:

    http://localhost:8080/hello/
    

To Undeploy the Sample Application Automatically

  1. Change to the domain's autodeploy directory.
    cd as-install/domains/domain-name/autodeploy
  2. Use the rm command to undeploy and remove the application.
    rm hello.war
    Use del instead of rm on Windows systems.

 

How to create war file through command line

For create war file first we need to create web application. 
  1. For that create a hello folder in D:\ drive. 
  2.  In hello folder create WEB-INF folder and create either index.html file or index.jsp file beside WEB-INF folder.
  3. Inside WEB-INF folder create classes folder, lib folder and create web.xml file also.
Now the web application is ready to create war file. Now you can check structure of hello application.


 

In next step for create war file in command line type D:\hello>jar -cvf hello.war *

  

now you can check structure of hello application in hello folder hello.war file is created.

How to start GlassFish server manually

After installed GlassFish Server open C:\glassfish3\bin folder then double click on asadmin batch file .

   

then write start-domain



Here actual HTTP port number is 8080 but here our HTTP port number is 9866
then type in Browser http://localhost:9866/    then click on go to the Administration Console.

 
 


Then give User Name and Password then click on Ligin button. Here our User Name is admin and Password is admin.


   
 

then you will get home page of GlassFish server.