wood burning stoves 2.0*
The moose likes JSP and the fly likes Unable to use tag file deployed in jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Unable to use tag file deployed in jar file" Watch "Unable to use tag file deployed in jar file" New topic
Author

Unable to use tag file deployed in jar file

Dinkar Chaturvedi
Ranch Hand

Joined: Mar 27, 2007
Posts: 42

Hello Folks,
I tried using a simple tag file the code of which is given as below

File: field.tag


I called it in a JSP whose code is as below

File: jartagfile.jsp


I put the tag file into a jar file using the command
"jar cvf tagfile.jar ."
I issued this command from the directory that contains META-INF\tags\field.tag. After the command i got the jar file which i placed in WEB-INF\lib

Since this tag file is a part of a jar file, I placed a tag in my TLD as follows:


When I try to access the jartagfile.jsp, I am getting the following exception:


Can anyone tell me whats the problem and how can i resolve it?

Regards
Dinkar
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I think that you have to put the TLD in the META-INF of the JAR file (but I'm not 100% sure, I've never made JAR packed tag files)


[My Blog]
All roads lead to JavaRanch
Dinkar Chaturvedi
Ranch Hand

Joined: Mar 27, 2007
Posts: 42

I was wondering if the directive I added in my JSP for the tag file is correct or not.

I read that we must provide the location of the tagfile in the "tagdir" attribute of the directive. Is the way, I have done, the correct way of mentioning the location of the tag file? I mean, how do you indicate the location of a tag file which is inside a jar file?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61229
    
  66

Originally posted by Dinkar Chaturvedi:
I was wondering if the directive I added in my JSP for the tag file is correct or not.


Of course it's not. That directive is telling the container to look in the WEB-INF/tags folder of the web app, and the tag's not there.

Within the TLD file of the tag library, you would declare the tag like this example:



Note that you can create sub-folders under META-INF. Then place the tag file in the META-INF/whatever folder within the jar file.

Now here's the part that you might be missing: the TLD file for the jarred tag must be within the jar file itself in the META-INF folder.

This way, you can create jar files that are self-contained tag libraries, where there's no need to do anything but drop the jar file (or files as in the case of the JSTL) into the WEB-INF/lib, and then use the appropriate tag declaration on the pages.

You cannot reference the jarred tag file from a TLD that is not in the jar file.
[ April 06, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Georges-Etienne Legendre
Greenhorn

Joined: Jul 18, 2007
Posts: 1
What would be the appropriate tag declaration?
How would I declare the tag-lib in web.xml if I don't extract the tld file from the library?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61229
    
  66

Originally posted by Georges-Etienne Legendre:
How would I declare the tag-lib in web.xml if I don't extract the tld file from the library?


You don't. There is no need for a tag-lib declaration in the web.xml.

What would be the appropriate tag declaration?


The uri attribute of the taglib declaration in the JSP page must match the URI defined within the TLD which will be located within the jar file for the library (in the META-INF folder).

When the jar file is in the calsspath of the app (like in WEB=INF/lib), the container will automatically find it and match it up by URI.
 
wood burning stoves
 
subject: Unable to use tag file deployed in jar file