How to add TLD and Tag Lib files into a Maven's jar project

笑着哭i 提交于 2019-12-03 03:31:19

The practice these days is to put the TLD files into the tag library JAR and let the class loader find them. Download the Apache JSTL JARs and see how they do it. I'd recommend following that convention. It'll simplify your app too, because you won't have to declare the TLD in your web.xml file: just put the JAR in your CLASSPATH and make sure that the URI in your .jsp matches that in the TLD.

@duffymo - Your solution totally works. Adding graphic to your description.

Create a maven project that generates JAR. keep the structure like this below

 src -- main
            |-- java
            |      `-- net
            |            `-- madhur
            |                 `-- helloTag.java
            `-- resources
                  `-- META-INF
                        `-- tags
                             `-- customTags.tld

To your customTags.tld file add uri something like this

<uri>http://www.xyzabc.com/taglibs/customTags</uri>

Accessing tags in you WAR file

War should have following structure

  META-INF/
  META-INF/MANIFEST.MF
  WEB-INF/
  WEB-INF/classes/
  WEB-INF/lib/
  WEB-INF/lib/{tagLibrary}.jar
  WEB-INF/web.xml
  WEB-INF/customTags.tld

web.xml

    <jsp-config>
        <taglib>
            <taglib-uri>www.xyzabc.com/taglibs/customTags</taglib-uri>
            <taglib-location>/WEB-INF/customTags.tld</taglib-location>
        </taglib>
    </jsp-config>

Using tag in FTL or JSP file

Ftl:

<#assign ct = JspTaglibs["www.xyzabc.com/taglibs/customTags"]>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!