Wednesday, July 4, 2012

Packaging your TLDs with Maven

Packing your TLDs files with Maven can be very useful to allow systematic reuse of these resources. It is also fairly easy to accomplish.
First add the Maven resource plugin to your build. In pom.xml, locate (or create) the build/plugins section and add the following

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
</plugin>

No configuration needed if you respect the conventions shown below.
Resource files in Maven are by default located in folder src/main/resources. Include it in your build path if it isn't yet (if necessary, create it) as a resource folder.
Create the subdirectory META-INF under the src/main/resources and place your tld file here. Don't forget to specify the uri node, as follows

<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2eeweb-jsptaglibrary_2_0.xsd" version="2.0">
 <tlib-version>1.0</tlib-version>
 <uri>http://core.jcz.org</uri>

 <function>
 ....
 </function>
</taglib>

That's it! Now your TLD will be placed in your JAR.
Also using it is very simple. Just follow this link.

No comments:

Post a Comment