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.
Script: redeploy.sh
#!/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
I am looking for deployment scripts for glassfish servers. i.e scripts to start/stop servers, deploy application, copy jar/war files to lib folders, delete files form a specific location, update properties files etc .
pls let me know your thoughts.. Appreciate your help.
Deployment script for glassfish should be simple to create.
1. Doing start/stop can be easily done using asadmin commands shown in this post redeploy.sh
2. Copy jar/war files to lib folders : This could be application specific script. You can use several options for that ant/maven or unix script etc.
3. Delete files from specific location : Again this can be easily done using unix script a simple rm command can be run in script.
4. update Properties files: I have done this in past using Ant. Ant has a replace content task which is specifically from property files. I am sure there is a way in Maven also to do similar stuff.
The GlassFish admin console, RESTful interface, and asadmin CLI all call the same code to execute a command. If it works for one, it should work for the others (assuming option/valuess are correct).
when i am trying this to deploy an ear file , i am getting an error like: any help
Usage: deploy [–terse=false] [–echo=false] [–interactive=true] [–host localhost] [–port 4848|4849] [–secure | -s] [–user admin_user] [–passwordfile file_name] [–virtualservers virtual_servers] [–contextroot context_root] [–force=true] [–precompilejsp=false] [–verify=false] [–name component_name] [–upload=true] [–retrieve local_dirpath] [–dbvendorname dbvendorname] [–createtables=true|false | –dropandcreatetables=true|false] [–uniquetablenames=true|false] [–deploymentplan deployment_plan] [–enabled=true] [–generatermistubs=false] [–availabilityenabled=false] [–libraries jar_file[(pathseparator)jar_file]*] [–target target(Default server)] filepath
CLI010 Value not specified for port
Awesome — thanks for posting beginner commands that are immediately relevant without all the noise! Cheers!