Deploying Applications to GlassFish Using curl
Thursday, February 10, 2011 |Over the past few months, I’ve been posting tips on how to use the REST interface in GlassFish v3 and later to perform various functions. My last post used Scala. In this much briefer and far less ambitious post, I thought I’d share how to deploy an app using curl (from the shell of your choice). If you’re familiar with the REST endpoint, there’s really not just a whole lot new here:
1
2
3
4
5
curl -s -S \
-H 'Accept: application/json' -X POST \
-H 'X-Requested-By: dummy' \
-F id=@/path/to/application.war \
-F force=true http://localhost:4848/management/domain/applications/application
Remember that the actual archive contents are passed as the value to the parameter id
, so we tell curl
to send the contents of the file using the prefix @
. The context root and application will be deduced by the system (or can be specified by passing contextroot
and name
parameters). The force
parameter tells GlassFish to force the deployment even if an application is already deployed under that name (which is effectively a redeployment).
As an added bonus, to undeploy, you can issue this:
1
2
3
4
curl -s -S \
-H 'Accept: application/json' \
-H 'X-Requested-By: dummy' \
-X DELETE http://localhost:4848/management/domain/applications/application/$APPNAME
It’s as simple as that. If you’re using a shell script, you could always just use asadmin directly, of course. Using that approach, asadmin must be on the PATH, or you have to specify the full path in your script, so your choice comes down to preference, I think. Either way, now you know how to do both. :)