Custom Javadoc Tag for File Creation Timestamp

To embed a file creation timestamp in Javadoc documentation, define a custom tag and integrate it into your source comments. The standard Javadoc tool does not natively support dynamic timestamps, so the timestamp must be generated at build or documentation-generation time.

Begin by annotating your class with a custom @created tag in the Javadoc comment:

/**
 * Utility for managing document metadata.
 * @created 2024-06-15T10:30:00Z
 */
public class DocumentMetadata {
    // Class implementation
}

To automate timestamp insertion during documentation generation, use a preprocessing step before invoking javadoc. For example, a build script (e.g., in Maven, Gradle, or a shell script) can inject the current ISO 8601 timestamp into source files or pass it as a substitution token.

Alternatively, extend Javadoc by implementing a custom doclet. Below is a minimal example using the legacy com.sun.tools.javadoc API (note: this API is internal and deprecated in modern JDKs):

import com.sun.javadoc.*;
import com.sun.tools.javadoc.Main;

public class TimestampDoclet {
    public static boolean start(RootDoc root) {
        String timestamp = java.time.Instant.now().toString();
        for (ClassDoc cls : root.classes()) {
            System.out.println("Processing " + cls.name() + ", created: " + timestamp);
            // Custom logic to attach timestamp to output
        }
        return true;
    }

    public static void main(String[] args) {
        String[] options = {
            "-doclet", "TimestampDoclet",
            "-d", "docs",
            "DocumentMetadata.java"
        };
        Main.execute(options);
    }
}

When generating documentation, run:

javadoc -doclet TimestampDoclet -d docs DocumentMetadata.java

This approach allows dynamic inclusion of creation timestamps in generated documentation, though modern projects typically prefer build-time templating or external documentation systems for such metadata.

Tags: java javadoc documentation timestamp custom-tag

Posted on Fri, 08 May 2026 23:02:49 +0000 by pseudonym