Taglib inside Maven dependency jar. How do I configure this taglib inside the web.xml?

风格不统一 提交于 2019-12-10 10:59:25

问题


So I used to configure my taglib like that:

<jsp-config> 
   <taglib> 
      <taglib-uri>myTags</taglib-uri> 
      <taglib-location>/WEB-INF/lib/mylib-2.0.1.jar</taglib-location> 
   </taglib> 
</jsp-config>

But now mylib-2.0.1.jar is a maven dependency, so of course it is NOT on /WEB-INF/lib.

How do I do to configure my taglib so I can do that in my JSPs:

<%@ taglib uri="myTags" prefix="mt" %>

EDIT1: To clafiry, the taglib.tld is inside the META-INF inside the jar so you can access the tld by referencing the jar itself. That's a convenient way to distribute your taglib along with the web application framework jar.

EDIT2: When we deploy the webapp, the jar will be in the WEB/INF/lib. But during development, inside eclipse, using m2eclipse, the jar will NOT. So eclipse complains it cannot find the taglib no where, because the jar is not there and I cannot reference my jar in the web.xml.


回答1:


You do not need to configure anything in web.xml, if the taglib is in \META-INF\taglib.tld inside your jar, it is automatic, Tomcat already recognizes.

You can use the jsp :

<% @ Taglib prefix = "my" uri = "http://www.mytags.com/"%>



回答2:


If you add in your POM the taglig dependency, it will be added in the WEB-INF/lib directory of your webapp.

  <dependency>
     <groupId>yourTageLib</groupId>
     <artifactId>mylib</artifactId>
     <version>2.0.1</version>
     <scope>compile</scope>
  </dependency>


来源:https://stackoverflow.com/questions/7682680/taglib-inside-maven-dependency-jar-how-do-i-configure-this-taglib-inside-the-we

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!