如何将TLD和Tag Lib文件添加到Maven的jar项目中 [英] How to add TLD and Tag Lib files into a Maven's jar project

查看:620
本文介绍了如何将TLD和Tag Lib文件添加到Maven的jar项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven项目打包成 jar



而且我也有一个Maven项目被打包为 war 。这个战争项目有一个tld文件和一些xhtml文件(标签库)。战争项目的结构是(基本上):

  pom.xml 
src
main
java
...
webapp
WEB-INF
my-facelets.taglib.xml
facelets
aTag.xhtml
anotherTag .xhtml
META-INF
my-facelets.taglib.tld

然后出现了将这些xml,xhtml和tld文件从war项目中删除并将其打包到jar项目中的要求。所以我的第一个尝试是在jar项目的POM中添加:

 < resources> 
< resource>
< directory> src / main / tld< / directory>
< targetPath> META-INF< / targetPath>
< / resource>

< resource>
< directory> src / main / taglib< / directory>
< targetPath> WEB-INF< / targetPath>
< / resource>
< / resources>

将文件放在 src / main / tld (我想要导出到 META-INF )和 src / main / taglib (我想要导出到 WEB-INF )。根据我的意图创建jar:

  myjar 
com
我的

WEB-INF

META-INF
my-facelets.taglib.tld
WEB-INF
...

然后我将这个新的jar添加到我的第一个战争项目中,作为一个maven依赖。



问题是那些罐内的META-INF,WEB-INF(jar里面的那个.tld,.xhtml,.xml文件在war的 WEB-INF / lib )不被识别。显然,他们应该直接进入战争结构,除非执行一些其他配置。这是一个必须的要求,因为多个战争项目将使用jar项目的特性(类和taglib)。

解决方案

这几天的做法是将TLD文件放入标签库JAR,让类加载器找到它们。下载Apache JSTL JAR,看看它们是如何实现的。我建议遵循这个惯例。它也将简化您的应用程序,因为您不必在web.xml文件中声明TLD:只需将JAR放在CLASSPATH中,并确保.jsp中的URI与TLD中的URI匹配。 p>

I have a Maven project that is packaged as jar.

And I also have a Maven project that is packaged as war. This war project has a tld file and some xhtml files (the tag libs). The structure of the war project is (basically):

pom.xml
src
    main
       java
           ...
       webapp
           WEB-INF
               my-facelets.taglib.xml
               facelets
                   aTag.xhtml
                   anotherTag.xhtml
           META-INF
               my-facelets.taglib.tld

And then appeared a requirement to remove those xml, xhtml and tld files from the war project and package them into the jar project. So my first try was add in the jar project's POM:

<resources>
  <resource>
    <directory>src/main/tld</directory>
    <targetPath>META-INF</targetPath>
  </resource>

  <resource>
    <directory>src/main/taglib</directory>
    <targetPath>WEB-INF</targetPath>
  </resource>
</resources> 

And put the files, of course, into src/main/tld (the ones I wanted to export into META-INF) and src/main/taglib (the ones I wanted to export into WEB-INF). And the jar was created as I wish:

myjar
    com
        my
            classes
    WEB-INF

    META-INF
        my-facelets.taglib.tld
    WEB-INF
        ...

And then I added this new jar to my first war project, as a maven dependency.

The problem is that those .tld, .xhtml, .xml files that are inside the jar's META-INF, WEB-INF (the jar is inside war's WEB-INF/lib) are not recognized. Apparently they should be directly into the war structure, unless some other configuration is performed. This is a must-have requirement, because multiple war projects will use the features (classes and taglibs) of the jar project.

解决方案

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.

这篇关于如何将TLD和Tag Lib文件添加到Maven的jar项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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