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 DomainTo run the asadmin command for deployment you need to start the domain first using below command
asadmin start-domain domain1
Deploy war fileOnce 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 serverYou 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 onceIts 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.
#!/bin/sh ## 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
redeploy.sh myapp [warlocation]/myapp.war