May 26 2009

Eclipse – Project Facets

Category: EclipsePhil @ 7:38 pm

This Eclipse feature has been around for a couple years, but seems to stay hidden from most developers; probably because they have not had a chance to take advantage of the Dynamic Web project type. It seems like once a project is setup, nobody ever wants to change it! The Dynamic Web project type is used in conjunction with the Eclipse Web Tools Platform (WTP) plug-in, which has been on my “Upcoming” list for some time now…

<HISTORY>I was a huge fan of the MyEclipse plug-in suite a few years ago; it was a predecessor to the nicely bundled Eclipse distributions that can be downloaded today. MyEclipse provided a very elegant Eclipse / Weblogic integration capability; as well as many other nice features that otherwise were difficult to manually enable. I worked with many different teams and it was always a hassle to convince them to purchase or convert their projects to the structure required by MyEclipse. As I became more familiar with the Ganymede release and the maturing Web Tools Platform plug-in, this Eclipse bundle seemed to be a much easier to sell and better alternative. MyEclipse is still a very popular and well put together product; be as I recall, it always took them too long to catch up with the current Eclipse versions, which I was fond of using as well.</HISTORY>

To use WTP, your project needs to have some additional features, namely Facets. Facets are used to define characteristics and requirements for Java EE projects. Originally, only Java EE projects had Facets; but this seems to be changing. I recently added some J2EE Module Dependencies to a web project, Eclipse enabled Facets in the simple Java project included as a dependency. To convert an existing project to a Faceted project, you need to manually modify your .project file. It is best to only enable Facets and let Eclipse add the additional nature; these natures will be added as you enable extra characteristics. To convert a Java Project to a Web Project, modify the .project file and add the following two lines.

<nature>org.eclipse.wst.common.project.facet.core.builder</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
 

You will not notice any visual difference in your project after making this change. However, if you open up your project’s properties and search for the word facet, you will see a new configuration option. At this point, you can select the Dynamic Web Module option and configure your runtime environment (Tomcat, Jetty, etc).

If you have successfully converted your project, you will see a small globe appear on the project folder icon. You can now add the project to the Servers view and easily deploy the project in your locally configured runtime environment. I have glossed over some of the WTP setup, but will cover that in another post. I thought it was important to explain Facets; I had previously wasted significant time, manually converting projects to Dynamic Web projects. Unfortunately, the manual approach only worked about 50% of the time. Once I learned about Facets, it made my life a lot easier!

FYI, the (S) on the folder, next to the globe, indicates a Spring IDE plug-in enabled project.  If you are developing Spring-based applications, you have to install this plug-in; it makes creating and managing your context files many times simpler.

https://www.beilers.com/wp-content/plugins/sociofluid/images/digg_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/reddit_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/dzone_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/delicious_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blinklist_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/blogmarks_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/google_48.png https://www.beilers.com/wp-content/plugins/sociofluid/images/facebook_48.png

One Response to “Eclipse – Project Facets”

  1. Dan says:

    Very helpful! I tend not to put .classpath and .project into source control, due to differences on development machines, and of course paths are different. So if you don’t import the project _just_right_, you won’t end up with a faceted project. Then it’s impossible to add the facets you want!
    Before I had resorted to reimporting until I got it right; I wasn’t sure what other magic eclipse was doing in the background. Just added those two lines to the list of natures, and now it’s working great, I can convert it to a DWP.

Leave a Reply