Wednesday, November 01, 2006

Adding the portlet.xml schema to Eclipse

Updated 2007-04-12: Fixed the instructions. Seems the old ones don't work any longer.

I finally figured out how to do this. The inferred XML schema support in Eclipse is pretty nice and usually suffices, but sometimes I want to have completion based upon full schema knowledge. Here's how to add the portlet.xml XSD file to Eclipse:
  1. First you need to have the JSR 168 code, so go there and get it.
  2. For Eclipse you'll need WTP installed. Get Eclipse 3.2 and use Callisto Discovery Site to download WTP as well.
  3. Okay, now in Eclipse's preference window, go to Web and XML > XML Catalog. Click Add ....
  4. In the URI field, click the little arrow and select the portlet-app_1_0.xsd file that you downloaded in the JSR 168 release.
  5. In Key Type field select Schema Location. Then in the Key field, enter the schema location that you will be using in your portlet.xml files. I entered
  6. Click OK, OK.
  7. Then you need to make sure you have the following entries in the root element (portlet-app) in your portlet.xml file:
    • [Added 2007-04-12] xmlns=""
    • xmlns:xsi=""
    • xsi:noNamespaceSchemaLocation=""
    • [Updated 2007-04-12] xsi:schemaLocation=""
  1. Then if you already have a portlet.xml file loaded you'll need to go to XML > Reload Dependencies. Then you should have tag completion in your portlet.xml files.
For more information, here is the corresponding entry from the Eclipse help documentation. I should note that Eclipse seems to think there are errors in the portlet xsd file, but this doesn't seem to cause any problems, i.e., the tag completion works properly.

I should note also that this approach works for other XSD files as well. I recently also used these steps to get schema support for Maven2 pom.xml files.

No comments: