Background:
I have several projects that should share a packaged tag file (see the section Packaged tag files). In a standalone project, I created this packaged tag file, which is actually just a JAR file (refer to the section 'JAR file structure' below) that I can redistribute to all of my projects. I am using Eclipse IDE.
Problem:
According to the Oracle docs, I should be able to put my .tld into the JAR file's /META-INF/ directory. However, Eclipse only validates my code successfully if the .tld is also in the project's /WEB-INF/ directory and I reference it with <%@taglib prefix="t" uri="/WEB-INF/tagfiles.tld" %>
. How do I reference my tag in Eclipse without putting the .tld into the /WEB-INF/ directory? Here is the Oracle documentation stating it can be in the JAR's META-INF:
Tag library descriptor file names must have the extension .tld and must be packaged in the /WEB-INF/ directory or subdirectory of the WAR file or in the /META-INF/ directory or subdirectory of a tag library packaged in a JAR. If a tag is implemented as a tag file and is packaged in /WEB-INF/tags/ or a subdirectory, a TLD will be generated automatically by the web container, though you can provide one if you wish.
The reason I don't want to put the .tld into the WEB-INF is that it's easier to distribute if it's contained in the JAR. Then I don't have to re-copy it to all of the dependent projects every time I make a change.
My JAR file structure:
I created a JSP tag file called wrapper.tag. I created another file called tagfiles.tld with a tag-files
element which has a child element <path>/META-INF/tags/wrapper.tag</path>
. I created an ant task which JARs these. It creates a JAR with the following contents: a META-INF, META-INF/tags, META-INF/tld, META-INF/MANIFEST.MF, tags/wrapper.tag, and tld/tagfiles.tld.