{"id":33831,"date":"2016-04-22T13:37:26","date_gmt":"2016-04-22T08:07:26","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=33831"},"modified":"2016-04-25T09:58:12","modified_gmt":"2016-04-25T04:28:12","slug":"grails-3-and-deployment-to-tomcat-container","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/grails-3-and-deployment-to-tomcat-container\/","title":{"rendered":"Grails 3 and Deployment to Tomcat Container"},"content":{"rendered":"<p>Any web application consists mainly of two tasks, i.e, development, and deployment. For <a title=\"grails development\" href=\"http:\/\/www.tothenew.com\/grails-application-development\">web application development<\/a>, we can use any tools but for deployment, we need to be careful of what environments are supported by the framework.<\/p>\n<p>At the time of Grails 2, we just needed to execute\u00a0<strong>grails war<\/strong> and put the generated war to a container, most probably Tomcat&#8217;s <strong>webapps<\/strong> folder, and optionally\u00a0restarting the container.<\/p>\n<p>Starting with Grails 3, it&#8217;s much simpler, due to the embedded, default, Tomcat container, which is specified inside the\u00a0<strong>build.gradle<\/strong> as follows:<\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<\/p>\n<p>dependencies {<br \/>\n    compile &quot;org.springframework.boot:spring-boot-starter-tomcat&quot;<br \/>\n}<\/p>\n<p>[\/sourcecode]<\/p>\n<p>We just need to execute\u00a0<strong>grails war\u00a0<\/strong>or\u00a0<strong>.\/gradlew bootRepackage<\/strong> and then execute the resulted war using <strong>java -jar build\/libs\/my-app-0.1.war<\/strong>. This would listen by default on port 8080.<\/p>\n<p>See! No more specialized containers!<\/p>\n<p>But wait, what if we need to deploy it to a container? Just putting this resulted war inside Tomcat&#8217;s webapps folder won&#8217;t work anymore.<\/p>\n<p>Any workaround? Yes, there is.<\/p>\n<p>Just change the scope of Tomcat&#8217;s dependency to <strong>provided<\/strong> from the <strong>compile<\/strong> as shown below:<\/p>\n<p>[sourcecode language=&#8221;java&#8221;]<\/p>\n<p>dependencies {<br \/>\n    provided &quot;org.springframework.boot:spring-boot-starter-tomcat&quot;<br \/>\n}<\/p>\n<p>[\/sourcecode]<\/p>\n<p>And then just generate the war and run it any way you want. Easy right?<\/p>\n<p>The bonus is, our development environment is still intact by this change of the dependency scope, we are still running our\u00a0<strong>grails run-app\u00a0<\/strong>without any issue.<\/p>\n<p>As a note on the Tomcat version, we need to use <strong>Tomcat 7.0.55<\/strong>, or else it won&#8217;t work. I&#8217;m currently using <strong>Grails 3.1.4<\/strong>. More information on supported containers can be found at https:\/\/grails.org\/wiki\/Deployment.<\/p>\n<p>For further information on this topic head to\u00a0http:\/\/grails.github.io\/grails-doc\/3.1.4\/guide\/deployment.html.<\/p>\n<p>Thanks for reading till here. See you next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Any web application consists mainly of two tasks, i.e, development, and deployment. For web application development, we can use any tools but for deployment, we need to be careful of what environments are supported by the framework. At the time of Grails 2, we just needed to execute\u00a0grails war and put the generated war to [&hellip;]<\/p>\n","protected":false},"author":70,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":9},"categories":[7],"tags":[1366,3219,3221,3222,17],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/33831"}],"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\/70"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=33831"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/33831\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=33831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=33831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=33831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}