{"id":655,"date":"2012-01-16T05:53:44","date_gmt":"2012-01-16T05:53:44","guid":{"rendered":"http:\/\/www.gmarwaha.com\/blog\/?p=655"},"modified":"2014-09-14T04:43:07","modified_gmt":"2014-09-14T04:43:07","slug":"tomcat-intellij-deploy-war-files-outside-webapps-folder","status":"publish","type":"post","link":"https:\/\/www.gmarwaha.com\/blog\/2012\/01\/16\/tomcat-intellij-deploy-war-files-outside-webapps-folder\/","title":{"rendered":"Tomcat &#038; IntelliJ &#8211; Deploy war files outside webapps folder"},"content":{"rendered":"<p>At present I am working on developing an <strong>Android<\/strong> application that needs to be supported by a slew of REST services hosted in the cloud. I chose <a href=\"https:\/\/appengine.google.com\/\" title=\"Google App Engine\">Google App Engine<\/a> based on its support for Java, Groovy and most importantly Spring. I developed a Spring MVC based REST application and used <em>ContentNegotiatingViewResolver<\/em> to negotiate content based on request URL extensions. For example, an XML response will be returned if the request URL ends with <em>.xml<\/em>, a JSON response for <em>.json<\/em> and an HTML response if he URL doesn\u2019t have any extension. Don&#8217;t get me started on Accept Header versus URL extension based content negotiation. That is a rant for another day. <\/p>\n<p>I was attempting to Serialize a <em>Map&lt;Enum, List&lt;Model&gt;&gt;<\/em>. All was well and I was able to retrieve both HTML and JSON representations, but when I tested retrieving the XML representation, <em>JAXB<\/em> complained that it cannot handle a <em>Map<\/em> instance in the root although <em>Jackson<\/em> was totally cool about it. As usual, Googling revealed that JAXB expected a Container class at its root which I didn&#8217;t want to create. I didn&#8217;t want to give up either. So, I tried my luck using <em>XStreamMarshaller<\/em>. This time GAE complained that XStream used a restricted API. WTH?<\/p>\n<p>Just out of curiosity, I wanted to check if XStreamMarshaller would work as expected when used outside of GAE. So, I created a Tomcat context file &#8220;myapp.xml&#8221; with the following definition and carefully placed it inside <em>TOMCAT_HOME\/conf\/Catalina\/localhost<\/em>. I could have just started Tomcat from <em>TOMCAT_HOME\/bin\/startup.bat<\/em> to check if it works, but being an IDEA addict, I created a Run Configuration for the IDEA Tomcat plugin and started the server from inside IDEA. But the app refused to even be discovered, let alone be deployed. After a few frustrated attempts, I tried starting Tomcat directly outside IDEA. Thankfully the app got deployed successfully and to my surprise, the XStreamMarshaller skillfully streamed out the serialized XML. Problem Solved!<\/p>\n<pre class=\"prettyprint\">\r\n&lt;?xml version='1.0' encoding='utf-8'?&gt;\r\n&lt;Context docBase=\"PATH_TO_MY_APP\"\r\n         reloadable=\"true\"\r\n         path=\"\/myapp\"&gt;\r\n&lt;\/Context&gt;\r\n<\/pre>\n<p>But, why didn&#8217;t the app get deployed when I started Tomcat from inside IDEA? After all, I have linked IDEA to my local Tomcat installation and the script it executes is clearly in my <em>TOMCAT_HOME\/bin<\/em> folder. Then, why why why in the world does the app refuse to be discovered? The solution came in the form of CATALINA_BASE. It seems that IDEA copies the contents of <em>TOMCAT_HOME\/conf<\/em> folder into its HOME folder with some name like <em>Unnamed_MyApp<\/em> and sets this folder to be the <em>CATALINA_BASE<\/em>. That explains why &#8220;myapp.xml&#8221; is so totally ignored by Tomcat. Then, I navigated to &#8220;Tomcat Run Configuration -> Startup\/Connection -> Environment Variables&#8221; and added CATALINA_BASE as an environment variable and pointed it to your local TOMCAT_HOME folder. After this configuration change IDEA started Tomcat as expected and my app was both discovered and deployed. Another Problem Solved!<\/p>\n<p>But the real problem &#8211; JAXB complaining about Map and GAE rejecting XStreamMarshaller as restricted &#8211; is yet to be solved. Maybe I should try one of the CastorMarshaller, XmlBeansMarshaller or JibxMarshaller. <\/p>\n<p>Any ideas?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At present I am working on developing an Android application that needs to be supported by a slew of REST services hosted in the cloud. I chose Google App Engine based on its support for Java, Groovy and most importantly Spring. I developed a Spring MVC based REST application and used ContentNegotiatingViewResolver to negotiate content based on request URL extensions. For example, an XML response will be returned if the request URL ends with .xml, a JSON response for .json and an HTML response if he URL doesn\u2019t have any extension. Don&#8217;t get me started on Accept Header versus URL... <br \/><a class=\"moretag\" href=\"https:\/\/www.gmarwaha.com\/blog\/2012\/01\/16\/tomcat-intellij-deploy-war-files-outside-webapps-folder\/\">Continue reading...<\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,16,33,15,18,10,36,32,17],"tags":[],"class_list":["post-655","post","type-post","status-publish","format-standard","hentry","category-android","category-groovy","category-ide","category-modern-languages","category-mobile","category-serverside","category-spring","category-technology","category-tomcat"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.gmarwaha.com\/blog\/wp-json\/wp\/v2\/posts\/655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gmarwaha.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gmarwaha.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gmarwaha.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gmarwaha.com\/blog\/wp-json\/wp\/v2\/comments?post=655"}],"version-history":[{"count":17,"href":"https:\/\/www.gmarwaha.com\/blog\/wp-json\/wp\/v2\/posts\/655\/revisions"}],"predecessor-version":[{"id":788,"href":"https:\/\/www.gmarwaha.com\/blog\/wp-json\/wp\/v2\/posts\/655\/revisions\/788"}],"wp:attachment":[{"href":"https:\/\/www.gmarwaha.com\/blog\/wp-json\/wp\/v2\/media?parent=655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gmarwaha.com\/blog\/wp-json\/wp\/v2\/categories?post=655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gmarwaha.com\/blog\/wp-json\/wp\/v2\/tags?post=655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}