Search code examples
jspjsp-tagstaglib

Custom Taglib Compilation error


I am trying to create a taglib for my custom tag. But I am getting a compilation error in Eclipse IDE. Here is my TagLib description:

<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
  <tlib-version>1.0</tlib-version>  
  <uri>MyFunction</uri>
  <function>
      <name>myFunc</name>
      <function-class>com.tldcls.MyClass</function-class>
      <function-signature>int age()</function-signature>
  </function> 
</taglib>

I am getting a compilation error on the tag. The error tells:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'uri'.

I am not able to figure out where is the problem.


Solution

  • The XSD mentioned in the file (http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd) reveals that the taglib element has the following child elements, in this order

    • tlib-version
    • short-name
    • uri
    • ...

    The short-name is not optional, and it's supposed to be the suggested prefix to use for this taglib.