Tomcat & IntelliJ – Deploy war files outside webapps folder

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’t have any extension. Don’t get me started on Accept Header versus URL extension based content negotiation. That is a rant for another day.

I was attempting to Serialize a Map<Enum, List<Model>>. All was well and I was able to retrieve both HTML and JSON representations, but when I tested retrieving the XML representation, JAXB complained that it cannot handle a Map instance in the root although Jackson was totally cool about it. As usual, Googling revealed that JAXB expected a Container class at its root which I didn’t want to create. I didn’t want to give up either. So, I tried my luck using XStreamMarshaller. This time GAE complained that XStream used a restricted API. WTH?

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 “myapp.xml” with the following definition and carefully placed it inside TOMCAT_HOME/conf/Catalina/localhost. I could have just started Tomcat from TOMCAT_HOME/bin/startup.bat 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!

<?xml version='1.0' encoding='utf-8'?>
<Context docBase="PATH_TO_MY_APP"
         reloadable="true"
         path="/myapp">
</Context>

But, why didn’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 TOMCAT_HOME/bin 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 TOMCAT_HOME/conf folder into its HOME folder with some name like Unnamed_MyApp and sets this folder to be the CATALINA_BASE. That explains why “myapp.xml” is so totally ignored by Tomcat. Then, I navigated to “Tomcat Run Configuration -> Startup/Connection -> Environment Variables” 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!

But the real problem – JAXB complaining about Map and GAE rejecting XStreamMarshaller as restricted – is yet to be solved. Maybe I should try one of the CastorMarshaller, XmlBeansMarshaller or JibxMarshaller.

Any ideas?

Intellij IDEA key map for Eclipse

Eclipse and IDEA logo

It is not the least easy to switch to Eclipse after years of addiction to Intellij IDEA. IDEA is the best IDE I have worked with until now and will continue to remain that way until there is another visionary who attempts to improve the developer pleasure instead of just technical modularity. Eclipse may (or may not) have a better architecture, better design, better modularity, incomparable number of plug-ins and better written code than IDEA, but that doesn’t seem to attract the end developers like me.

I just love IDEA for the way it understands me, knows what I am trying to do at any moment and most importantly for the complete integrated development experience it gives. That doesn’t mean that Eclipse is not famous. Eclipse is very famous and many people love it too. But I think it is because it is free and more so because every other software vendor creates plug-ins for eclipse and that level of community support is not there for Netbeans or IDEA.

Anyways, recently when I had to switch to Eclipse for a few months for one particular development project, I was not a happy camper. I wanted to bring at least some level of IDEA like familiarity into Eclipse and with a happy accident I was able to get to the IDEA key scheme for Eclipse. I sincerely thank Santhosh for having created an Eclipse plug-in for that. It works as advertisied except for a very few gotchas.

To create an IDEA key scheme for your Eclipse Helios installation, download the plug-in from here. Drop the downloaded jar file into $ECLIPSE_HOME\plugins folder and restart Eclipse. Then goto Window -> Preferences -> General -> Keys and modify the scheme drop-down to change it from “Default” to “Intellij IDEA”. Click Apply and OK and you are done. Every key combination like Ctrl+N, Ctrl+Shift+N, Alt+F7, Shift+F6, Ctrl+F12, Ctrl+Shift+-, etc should work as expected.

It did not give me THE COMPLETE IDEA experience but I guess this is the best I could get for now. If anyone has any suggestions for a better IDEA experience please do share them in the comments section. I most definitely will be grateful.