Generate TLDs in NetBeans IDE 4.1 with XDoclet

Follow the Java trail in the NetBeans IDE 4.1 Tag Library Tutorial. At the end of the Java trail, you should have two taghandlers (i.e., written in Java, not in JSP syntax) called DisplayLogoTag.java and FormatTextTag.java, together with a tag library descriptor (TLD) file called SimpleTagLib.tld. That's how the tutorial ends, more or less, but in real life your tag handlers often change and evolve so that it can be time-consuming and boring to manually re-synchronize them with the TLD. Hence, to automate the process, we can use XDoclet from within the IDE to re-generate the TLD after changes have been made to the tag handlers. We can also add a menu item to our IDE project (but only if our IDE project is a free-form project) so that we can easily invoke the re-generation process.

Fast Track: Too lazy to create the application yourself? Or maybe you just want to see how TLD re-generation works, without creating the application. Either way, you can download the application here. And then open it in the IDE and take all the steps below to quickly set up the re-generation functionality.

  1. Download and extract XDoclet 1.2.2.

  2. Add XDoclet tags to the DisplayLogoTag.java tag handler.

    • Add this in the comment block directly above the class declaration (i.e., NOT above the package declaration):

      \* @jsp.tag name="DisplayLogoTag" bodycontent="empty"
    • Add this in the comment block directly above the setSize method:

      \* @jsp.attribute name="size" required="true" rtexprvalue="true" type="java.lang.String"
  3. Add XDoclet tags to the FormatTextTag.java tag handler.

    • Add this in the comment block directly above the class declaration (i.e., NOT above the package declaration):

      \* @jsp.tag name="FormatTextTag" bodycontent="scriptless"
    • Add this in the comment block directly above the setStyle method:

      \* @jsp.attribute name="style" required="true" rtexprvalue="true" type="java.lang.String"
  4. Create the webdoclet-based target in your project's build.xml file.

     <target name="webdoclet-tld" depends="init, init-xdoclet" 
         description="Regenerate TLD">
    
          <echo>+---------------------------------------------------+</echo>
          <echo>|                                                   |</echo>
          <echo>| C R E A T I N G    T L D                          |</echo>
          <echo>|                                                   |</echo>
          <echo>+---------------------------------------------------+</echo>
    
          <webdoclet destdir="${web.docbase.dir}/WEB-INF"            
                   excludedtags="@author"         
                        verbose="false">
                
              <fileset dir="${src.dir}">
                  <include name="\*\*/\*Tag.java"/>
              </fileset>
    
              <jsptaglib Jspversion="2.0" taglibversion="1.0" shortName="simpletaglib"
                            uri="http://netbeans.org/tlds/SimpleTagLib" 
                            filename="SimpleTagLib.tld" validateXML="true"/>
    
         </webdoclet>
    
     </target>

    If you add this target to a different Ant file, you can import it into your project's own build.xml file by including this line at the top of your build.xml file:

    <import file="path-to-external-Ant-file/name-of-Ant-file.xml"/>
  5. Optionally, you can set up a contextual menu for the project to invoke this target. But this is possible for free-form projects only. Alternatively, maybe you want to create a target that re-generates all the TLDs in all the projects in the IDE. In that case, you can add a menu item or toolbar button to the IDE itself (not to an individual project) to invoke the target.
  6. Now, when you invoke the webdoclet-tld target, Ant picks up all the information from the XDoclet tags that you've defined in the tag handlers. If, for example, you change a tag handler so that its body content is "scriptless" instead of "empty", you need only change the bodycontent value of the @jsp.tag XDoclet tag, run the webdoclet-tld target, and the TLD is re-generated with the updated information.

Note that XDoclet currently does not support JSP 2.0. Therefore, if your tag handlers extend SimpleTagSupport, XDoclet will not generate the TLD file correctly. Therefore, just before you invoke the target, change the SimpleTagSupport to TagSupport, and then change it back after you've finished re-generating the TLD.

Comments:

Dear Geertjan, Thank you very much for this article. However, I got the following question. To what specific directory within NetBeans I need to extract XDoclet? Thank you very much. Regards, Anatoly

Posted by Anatoly on May 14, 2005 at 04:48 AM PDT #

Anywhere you like! Once you've extracted it, create a property like this in your project.properties file: xdoclet.root.dir=c:/xdoclet-1.2.2 Check out Brian's article, because this is where I learnt everything I know on XDoclet: http://www.netbeans.org/kb/41/j2ee-server-integration.html Hope this helps, if not please leave another comment!

Posted by guest on May 17, 2005 at 04:01 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today