Eclipse WTP: A hidden gem

In my previous post, I lamented how hard it was to find the right tools to get started with developing Struts (and other web applications) in Eclipse. The solution I finally found was to use the Eclipse Web Tools Platform (WPT) plug-in.

Today, I was trying the Spring Framework out and wanted to quickly set it up in Eclipse. I was following along the tutorial from the sample chapter of The Spring 1.x Primer. Personally I think it is a terrible tutorial. There are too many things going on in that chapter; the author expects that the user should set up decently-sized web application with Spring, Hibernate, Struts and Ant and then refactor this web application through the book. The whole chapter was basically a set of instructions: do this, do that, don't worry about that since we will get to it in a later chapter. Needless to say, I think this is a bad way to introduce a framework especially if you are bundling it with other huge frameworks. This forces the user to come to grasp with four different things at the same time.

Moreover, the author was advocating using his tool to create a skeleton for the project. While I agree that this is a good approach - it was almost as simple to use as the Ruby on Rails generator - but his tool was a bit outdated. It was using an older version of Hibernate and an older version of Spring. Moreover his tool generated an older version of a project file for IntelliJ that had to be updated. At this point, I was rather frustrated because of all the dependency issues that had to be resolved.

Fortunately, a search for "best spring book" revealed this link. I found it useful to read through the articles on Dependency Injection before even attempting to program with Spring. There are two well-written articles on the web for that: one by Martin Fowler and another by Javid James. Both authors give good examples that motivate the use of Spring without the needless coupling with other frameworks. I respect them both as good authors since they are able to explain things succinctly without having to confusing the reader.

Anyway, I downloaded the source code for this article and then just set up a new Dynamic Web Project in Eclipse. The WTP plug-in created a directory structure that mimics what a normal web application should look like and I was able to just copy the source code into my project. WTP was clever enough that it has a pseudo library called Web App Libraries that will mimic what was stored in the WEB-INF/lib folder without making me configure it. The XML editor even had decent code-completion based on the XML schema. Additionally, it was easy to set up the project to work with Tomcat 5.5 and I could test the application out in Eclipse itself using the built-in web browser. All in all, I was pleasantly surprised with how well integrated the WTP is.

I am sure there are other hidden features of WTP that I have yet to discover. A cursory inspection reveals that there is built-in support for adding data sources either from a file, web service or database. However, if you need dedicated support for Spring (and not just an easy way to get started), then you should either use IntelliJ which has great support for Spring, Hibernate and Struts or you can try out the Spring IDE which is based on Eclipse. Personally, I believe one would have a higher chance of success with IntelliJ since using multiple plug-ins in Elcipse (especially plug-ins that are not part of the official Eclipse project) creates lots of nasty dependency and versioning issues.

There are two articles on the web discussing how to use an older version of the Eclipse WTP. One details how to create web applications with WTP. Another details how to create a web application that uses Struts and Hibernate with the WTP. There are rather good articles and I was surprised that not many people had bookmarked them on del.icio.us. Maybe most people just have not heard of the WTP plug-in.

The Eclipse WTP book was also recently published. I have always viewed the publication of a book for an open source project as a good indication that you will not be screwed in the future using it. A book is a good indication of user momentum; there are people who are interested in finding out how to use it. I have not read the book since I am only doing basic things with WTP and the help documentation suffices for my needs but I expect that it will be useful when you are dealing with more complex issues.


comments powered by Disqus