How to deploy web app using asadmin command on GlassFish Enterprise Server

I have always liked the command line deployment on any application server. Somehow, I still don't trust the web based admin console for deploying my war/ear file on any server. Many times I have observed that the server doesn't respond if there is a problem in deployment. Therefore I always prefer the asadmin command deployment on Glassfish Application server.

In this article I am going to describe few simple steps, which can be used to do web application deployment on glassfish server.

For deploying a war file on Sun's GlassFish enterprise server you can use following asadmin command line options

Start Domain

To run the asadmin command for deployment you need to start the domain first using below command

asadmin start-domain domain1

Deploy war file

Once the domain is running you can run the below command to deploy the application war file.

asadmin deploy -s --contextroot myapp [warlocation]/myapp.war

This will make you access your application at a url http://localhost:port/myapp. In case you want to deploy the war file as a different context root say mynewapp then you can use the command as show below.

asadmin deploy -s --contextroot mynewapp [warlocation]/myapp.war

This will make you access your application at a url http://localhost:port/mynewapp

Restart server

You can restart the GlassFish server by executing the stop and start commands one by one.

asadmin stop-domain domain1 
asadmin start-domain domain1

How to undeploy a web application from command line?

For undeploying an application you can use undeploy option for asadmin command like below

asadmin undeploy -s myapp

Create a script doing this all at once

Its always easier to create a script of all these commands and run it, below script can be used to do a redeploy after first deployment.

## Undeploy existing
asadmin undeploy -s $1
## Deploy
asadmin deploy -s --contextroot $1 $2
## Restart
asadmin stop-domain mydomain
asadmin start-domain mydomain

Above script can be used to do deployment using simple command as shown below myapp [warlocation]/myapp.war


Linux 1129183533891669702

Post a Comment Default Comments