{"id":27440,"date":"2015-10-08T17:30:29","date_gmt":"2015-10-08T12:00:29","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=27440"},"modified":"2015-10-09T11:24:32","modified_gmt":"2015-10-09T05:54:32","slug":"running-grails-application-on-jetty","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/running-grails-application-on-jetty\/","title":{"rendered":"Running GRAILS application on JETTY"},"content":{"rendered":"<p>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:<\/p>\n<ul>\n<li>Performance: Jetty focuses on multi-HTTP connections to reduce page load time significantly<\/li>\n<li>Smaller Memory Footprint: It also takes up a very small amount of the sever&#8217;s available memory so there is more of the memory resource left for the application, threads, caches, garbage collections etc.<\/li>\n<li>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.<\/li>\n<li>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.<\/li>\n<\/ul>\n<p>We will follow the following steps to run a GRAILS war on JETTY on an Ubuntu 15.04 system.<\/p>\n<ol>\n<li>Download the tar from <a href=\"http:\/\/download.eclipse.org\/jetty\/8.1.17.v20150415\/dist\/jetty-distribution-8.1.17.v20150415.tar.gz\">here<\/a>.<\/li>\n<li>For the sake of convenience, create a symlink as:\n<p>[js] ln -s jetty-distribution-8.1.17.v20150415.tar.gz jetty [\/js]<\/p>\n<\/li>\n<li>We need to set some variables beforehand as follows:\n<p>[js]echo &quot;export JAVA_HOME=\/usr\/lib\/jvm\/java-7-oracle<br \/>\nJETTY_HOME=\/home\/admin\/jetty\/<br \/>\nJETTY_PORT=9000<br \/>\nJETTY_HOST=0.0.0.0<br \/>\nexport TMPDIR=~\/tmp<br \/>\nexport LC_ALL=en_US.UTF-8<br \/>\nexport LANG=en_US.UTF-8&quot; &gt; ~\/.userSettings[\/js]<\/p>\n<\/li>\n<li>You can set your own JAVA_HOME variable. We will be running the application on port 9000.\n<p>[js]echo &quot;source ~\/.userSettings&quot; &gt;&gt; ~\/.bashrc[\/js]<\/p>\n<\/li>\n<li>Source your .bashrc file.<\/li>\n<li>Create a directory tmp in the user&#8217;s home directory.<br \/>\nJetty extracts some data from war files and to print the stacktrace.log file.<\/li>\n<li>To define where the war file is extracted , edit the jetty-webapps.xml file:\n<p>[js]vim ~\/jetty\/etc\/jetty-webapps.xml[\/js]<\/p>\n<\/li>\n<li>Add the following line before the closing of the &#8220;New&#8221; tag:\n<p>[js] &lt;Set name=&quot;tempDir&quot;&gt;&lt;New class=&quot;java.io.File&quot;&gt;&lt;Arg&gt;path to webapps directory\/&lt;\/Arg&gt;&lt;\/New&gt;&lt;\/Set&gt;<br \/>\nex: &lt;Set name=&quot;tempDir&quot;&gt;&lt;New class=&quot;java.io.File&quot;&gt;&lt;Arg&gt;\/home\/admin\/jetty\/webapps\/&lt;\/Arg&gt;&lt;\/New&gt;&lt;\/Set&gt;<br \/>\n[\/js]<\/p>\n<\/li>\n<li>Save and exit the file.<\/li>\n<li>To define a single log file for jetty: Edit the jetty-logging.xml file as:\n<p>[js]vim ~\/jetty\/etc\/jetty-logging.xml[\/js]<\/p>\n<p>Replace<\/p>\n<p>[js]&lt;Arg&gt;&lt;Property name=&quot;jetty.logs&quot; default=&quot;.\/logs&quot;\/&gt;\/yyyy_mm_dd.stderrout.log&lt;\/Arg&gt;[\/js]<\/p>\n<p>with<\/p>\n<p>[js]&lt;Arg&gt;&lt;Property name=&quot;jetty.logs&quot; default=&quot;.\/logs&quot;\/&gt;\/jetty.log&lt;\/Arg&gt;<br \/>\n[\/js]<\/p>\n<\/li>\n<li>You would be able to see jetty logs under ~\/jetty\/logs\/jetty.log when you start the jetty container.<\/li>\n<li>Setting the JAVA_OPTIONS:<br \/>\nEdit the jetty.sh file:<\/p>\n<p>[js]vim ~\/jetty\/bin\/jetty.sh[\/js]<\/p>\n<p>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.<\/p>\n<p>[js]JAVA_OPTIONS+=(&quot;-DbuildModule=admin -XX:MaxPermSize=1024m -Xms512m -Xmx2048m&quot;)[\/js]<\/p>\n<p>Save and exit the file.<\/li>\n<li>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.<br \/>\nEdit the jetty.xml file:<\/p>\n<p>[js]vim ~\/jetty\/etc\/jetty.xml[\/js]<\/p>\n<p>At the line:<\/p>\n<p>[js] &lt;Set name=&quot;port&quot;&gt;&lt;Property name=&quot;jetty.port&quot; default=&quot;8080&quot;\/&gt;&lt;\/Set&gt;[\/js]<\/p>\n<p>Replace 8080 with the desired port (in our case it will be 9000).<\/li>\n<li>If the application is configured to pick up some external configurations, the config files can be copied into the location:\n<p>[js]~\/jetty\/resources\/[\/js]<\/p>\n<\/li>\n<li>Copy the war file as ROOT.war at the location:\n<p>[js]~\/jetty\/webapps\/[\/js]<\/p>\n<\/li>\n<li>Execute the following to start the jetty container:\n<p>[js]bash ~\/jetty\/bin\/jetty.sh start[\/js]<\/p>\n<\/li>\n<li>Looking at the log file we can see the application coming up.\n<p>[js]tail -f ~\/jetty\/logs\/jetty.log[\/js]<\/p>\n<\/li>\n<li>Once the application is up, in the browser hit: {SERVER_IP}:9000.<\/li>\n<li>Your Application is now LIVE!<\/li>\n<\/ol>\n<p>A big thanks to Mr. Jayant Puri, Mr. Rishabh Jain and Mr. Tejprakash Sharma for the extended guidance and support.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s available memory so [&hellip;]<\/p>\n","protected":false},"author":178,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4},"categories":[7,1],"tags":[4840,2543,2540,2541,2544,2542],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/27440"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/178"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=27440"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/27440\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=27440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=27440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=27440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}