Maven依赖罐中的Taglib.如何在web.xml中配置此taglib? [英] Taglib inside Maven dependency jar. How do I configure this taglib inside the web.xml?

查看:146
本文介绍了Maven依赖罐中的Taglib.如何在web.xml中配置此taglib?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我过去通常是这样配置我的taglib的:

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

但是现在mylib-2.0.1.jar是一个Maven依赖项,因此当然不在/WEB-INF/lib上.

我该如何配置我的taglib,以便可以在我的JSP中做到这一点:

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

EDIT1 :为了简单起见,taglib.tld位于jar的META-INF内部,因此您可以通过引用jar本身来访问tld.这是一种将taglib与Web应用程序框架jar一起分发的便捷方法.

EDIT2 :部署Web应用程序时,该jar将位于WEB/INF/lib中.但是在开发过程中,使用m2eclipse在eclipse内部,jar将不会.因此eclipse抱怨它找不到taglib,因为该jar不存在,而且我无法在web.xml中引用我的jar.

解决方案

您无需在web.xml中进行任何配置,如果taglib位于jar内的\META-INF\taglib.tld中,则表示它是自动的,Tomcat已识别. /p>

您可以使用jsp:

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

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.

解决方案

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/"%>

这篇关于Maven依赖罐中的Taglib.如何在web.xml中配置此taglib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆