DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Languages
  4. Generate your TLD Using Java Annotations

Generate your TLD Using Java Annotations

Ignacio Coloma user avatar by
Ignacio Coloma
·
Feb. 24, 10 · Interview
Like (0)
Save
Tweet
Share
10.03K Views

Join the DZone community and get the full member experience.

Join For Free

If you are stuck with JSP and keeping your TLD files by hand (like me), you are probably ignoring the elephant in the room:

  • Tag classes must be kept up-to-date with the TLD by hand. This means duplicate effort, a.k.a. "XML sucks".
  • For any non-trivial tag library, inheritance is a fact. In order to avoid replication in the TLD, your libraries are bound to use some dark XML magic.
  • IDEs are extracting JSP coding hints from the TLD file, so you should be introducing your documentation in the TLD by hand.
  • You are probably not sacrificing Javadoc in the process, which implies maintaining duplicate documentation: java(doc) and TLD.
  • Make it triple, if you want online HTML documentation.
  • There is no way to document deprecated behavior.

This March I will be 35, which sucks. Last year my brother Carlos Coloma celebrated his 25-year-old anniversary reading his MSc project with his colleague Javier Alonso: Generating TLD and HTML documentation from java annotations. Today we are releasing it as an open source project, TLDGen.


Instant gratification: click here to check out the generated HTML documentation.

TLDGen is a standalone library that does not depend on Loom. This is an important requirement to be able to generate our own TLD files.

Download tldgen.jar and add it to your classpath

First you should extract tldgen.jar from the tldgen zip file or from maven (group org.extrema-sistemas, artifact maven). This jar file contains just the annotations to get you running:

package com.acme.tags;

import org.loom.tldgen.annotations.Attribute;
import org.loom.tldgen.annotations.Tag;
import org.loom.tldgen.annotations.BodyContent;

/**
* This comment will be included in the generated TLD and HTML
*/
@Tag(dynamicAttributes = true, bodyContent = BodyContent.SCRIPTLESS, example = "<l:sample name=\"foo\"/>")
public class SampleTag extends SimpleTagSupport {
@Attribute(required = true)
private String name;

/** @deprecated use name instead */
@Attribute
public void setFoo(String value) {
name = value;
}
}
package com.acme.tags;

import org.loom.tldgen.annotations.Function;

public class Functions {
/**
* * bar javadoc
* <p>
* this is a paragraph
* </p>
*/
@Function(displayName = "bar display name", example = "Function example")
public static void bar() {
}

@Function
public static void baz() {
}
}

Execute tldgen

You should download tldgen.zip from google-code, uncompress it somewhere and execute all in the same line (we are assuming a standard gradle project structure):


tldgen   -sourcepath src/main/java   
-subpackages com.acme.tags   
-tldFile src/main/resources/META-INF/acme-tags.tld   
-displayName "Acme Tag Library" 
-name acme   
-uri "http://acme.com/acme-tags.tld"   
-htmlFolder build/docs/tlddoc


This should generate the TLD docs in build/docs/tlddoc and one TLD file in src/main/resources/META-INF/acme-tags.tld. As an example, you can check out the Loom taglib documentation.

From http://icoloma.blogspot.com

Annotation Java (programming language)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Front-End Troubleshooting Using OpenTelemetry
  • Key Elements of Site Reliability Engineering (SRE)
  • HTTP vs Messaging for Microservices Communications
  • How To Choose the Right Streaming Database

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: