Running GRAILS application on JETTY

08 / Oct / 2015 by Prakashul 0 comments

Jetty is one of the many open source HTTP servers and servlet containers available today. The key features that help us decide to use Jetty are:

  • Performance: Jetty focuses on multi-HTTP connections to reduce page load time significantly
  • Smaller Memory Footprint: It also takes up a very small amount of the sever’s available memory so there is more of the memory resource left for the application, threads, caches, garbage collections etc.
  • Throughput: Since it has multi-HTTP connections and also has a focus on features such as SPDY and in future, HTTP 2.0, jetty can handle thousands of requests simultaneously.
  • Supports custom components: Jetty can support custom components for the desired behavior as Google did by using their own custom HTTP connector and session management extensions.

We will follow the following steps to run a GRAILS war on JETTY on an Ubuntu 15.04 system.

  1. Download the tar from here.
  2. For the sake of convenience, create a symlink as:

    [js] ln -s jetty-distribution-8.1.17.v20150415.tar.gz jetty [/js]

  3. We need to set some variables beforehand as follows:

    [js]echo "export JAVA_HOME=/usr/lib/jvm/java-7-oracle
    export TMPDIR=~/tmp
    export LC_ALL=en_US.UTF-8
    export LANG=en_US.UTF-8" > ~/.userSettings[/js]

  4. You can set your own JAVA_HOME variable. We will be running the application on port 9000.

    [js]echo "source ~/.userSettings" >> ~/.bashrc[/js]

  5. Source your .bashrc file.
  6. Create a directory tmp in the user’s home directory.
    Jetty extracts some data from war files and to print the stacktrace.log file.
  7. To define where the war file is extracted , edit the jetty-webapps.xml file:

    [js]vim ~/jetty/etc/jetty-webapps.xml[/js]

  8. Add the following line before the closing of the “New” tag:

    [js] <Set name="tempDir"><New class=""><Arg>path to webapps directory/</Arg></New></Set>
    ex: <Set name="tempDir"><New class=""><Arg>/home/admin/jetty/webapps/</Arg></New></Set>

  9. Save and exit the file.
  10. To define a single log file for jetty: Edit the jetty-logging.xml file as:

    [js]vim ~/jetty/etc/jetty-logging.xml[/js]


    [js]<Arg><Property name="jetty.logs" default="./logs"/>/yyyy_mm_dd.stderrout.log</Arg>[/js]


    [js]<Arg><Property name="jetty.logs" default="./logs"/>/jetty.log</Arg>

  11. You would be able to see jetty logs under ~/jetty/logs/jetty.log when you start the jetty container.
  12. Setting the JAVA_OPTIONS:
    Edit the file:

    [js]vim ~/jetty/bin/[/js]

    We can also set here other JAVA options such as HeapSize, permsize, adding a newrelic jar etc. Since many grails applications have a build module associated, we will set the JAVA_OPTIONS by adding the following line as per the desired configuration.

    [js]JAVA_OPTIONS+=("-DbuildModule=admin -XX:MaxPermSize=1024m -Xms512m -Xmx2048m")[/js]

    Save and exit the file.

  13. Jetty, by default, runs on port 8080. However, it can be configured to run the application on other ports as well, as in our case we are running the application on port 9000.
    Edit the jetty.xml file:

    [js]vim ~/jetty/etc/jetty.xml[/js]

    At the line:

    [js] <Set name="port"><Property name="jetty.port" default="8080"/></Set>[/js]

    Replace 8080 with the desired port (in our case it will be 9000).

  14. If the application is configured to pick up some external configurations, the config files can be copied into the location:


  15. Copy the war file as ROOT.war at the location:


  16. Execute the following to start the jetty container:

    [js]bash ~/jetty/bin/ start[/js]

  17. Looking at the log file we can see the application coming up.

    [js]tail -f ~/jetty/logs/jetty.log[/js]

  18. Once the application is up, in the browser hit: {SERVER_IP}:9000.
  19. Your Application is now LIVE!

A big thanks to Mr. Jayant Puri, Mr. Rishabh Jain and Mr. Tejprakash Sharma for the extended guidance and support.


Leave a Reply

Your email address will not be published. Required fields are marked *