Deploying Applications to GlassFish Using curl - No Fluff Just Stuff

Deploying Applications to GlassFish Using curl

Posted by: Jason Lee on June 17, 2013

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: pass::[more]

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:

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. :)

Jason Lee

About Jason Lee

Jason Lee is a Senior Java Developer for Sun Microsystems working on the GlassFish Administration Console, and is a member of the JSF 2.0 (JSR 314) Expert Group. Jason has extensive experience working with web-based technologies such as JavaServer Faces and Ajax, as well as enterprise technologies based on the GlassFish platform. He is currently the main developer of Mojarra Scales, working to create a set of high quality JSF components wrapping libraries such as the Yahoo! User Interface Library, as well as bring Facelets compatibility to JSFTemplating.

Jason has been writing software professionally since 1997 in a wide variety of languages and environments, including Java, PHP, C/C++, and Delphi on both Linux/Unix and Windows. You can read more about what Jason's working on at his blog at http://blogs.steeplesoft.com

Apart from work, he is currently serving as the president of the Oklahoma City Java Users Group, where he is an active member and presenter. More importantly, Jason is married to a beautiful woman and has two sons who, thankfully, look like their mother.

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »