0

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.

Community
  • 1
  • 1
KyleM
  • 4,445
  • 9
  • 46
  • 78

1 Answers1

0

Got it working. I upgraded to Eclipse Luna (at the time of this writing, the newest version). My main project has a 'Projects' reference on the Java build path to the project that contains the tag file JAR. The JAR itself has the file structure indicated in my post above. My .tld file has the following contents:

<taglib version="2.0" xmlns="http://java.sun.com/xml/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd">
    <tlib-version>2.0</tlib-version>
    <jsp-version>2.0</jsp-version>
    <short-name>mysname</short-name>
    <uri>http://anyuri.com/anything</uri>
    <description>
     Your description here
    </description>
  <tag-file>
    <description>This is just a test</description>
    <display-name>wrapper</display-name>
    <name>wrapper</name>
    <path>/META-INF/tags/wrapper.tag</path>
  </tag-file>
</taglib>

I should also note that I have an ANT build that packages the tag file JAR into the web application's WEB-INF/lib directory. This is required according to the documentation:

Tag files can be packaged in the /META-INF/tags/ directory in a JAR file installed in the /WEB-INF/lib/ directory of the web application. Tags placed here are typically part of a reusable library of tags that can be used easily in any web application.

KyleM
  • 4,445
  • 9
  • 46
  • 78