Packaging and distributing taglibs in a JAR

by vivin

This is more of a “note to self” than a “how to”.

If you’re trying to distribute tag files in a JAR, you need to put them under /META-INF/tags. You then need to create a TLD file that you also put under /META-INF/tags. If you have tags or functions that you created in Java, and want to distribute them alongside the tag files, you need to reference them in the TLD and package them in the same JAR (goes without saying).

If you want to do the same thing in maven, the location for the tag files and the tld file is different; you need to put them in src/main/resources/META-INF/tags. Then you can run mvn package and maven will create a JAR with your tags.

My directory structure in my maven project looks like this:

`-- main
    |-- java
    |   `-- net
    |       `-- vivin
    |           `-- regula
    |               `-- validation
    |                   `-- util
    |                       `--
    `-- resources
        `-- META-INF
            `-- tags
                |-- generate-validation.tag
                `-- regula-spring.tld

And my TLD file looks like this:



   <function-signature>boolean matches(java.lang.String, java.lang.String, java.lang.String)</function-signature>

   <function-signature>java.lang.String replaceUsingRegex(java.lang.String, java.lang.String, java.lang.String, java.lang.String)</function-signature>