This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes JBuilder 6 and custom tag-libraries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JBuilder 6 and custom tag-libraries" Watch "JBuilder 6 and custom tag-libraries" New topic
Author

JBuilder 6 and custom tag-libraries

Ian Ohlander
Greenhorn

Joined: Jun 15, 2002
Posts: 16
Hello. I have had a chance to lurk on this site and found it really great. So I really hope one of you can help me. Thank you.
I searched the JavaRanch Saloon for an answer and 'googled' up to about page 20 and still nothing.
I am using JBuilder 6 and I am trying to use a custom tag library that I wrote. My books tell me that taglibs are best distributed as .jar files with a particular structure.
So I have a taglib named cocTags.jar with the structure as follows: in root directory, the two tags (classes). Then there is a META-INF directory with the cocTags.tld.
I simple want to, in my coc project, use those tags. I have tried following suggestions in the books, like a direct taglib reference at the top of the jsp page, a reference in web.xml, and so forth. My problem is, in JBuilder how do I put my cocTags.jar in a lib directory under WEB-INF of the coc project? Sounds easy, right? I went into windows explorer and did it. But, when I compile, because JBuilder doesn't know anything about it, it erases that directory. So in JBuilder, I go to the structure pane (? I think that is what it is called- the top left window with the project directory structure.) and create a folder called lib, then add it to the project. The problem is, JBuilder adds it's reference, not the actual file. So cocTags.jar still resides in the c:\cocTags directory. I cannot manually put it into the c:\coc\WEB-INF\lib directory from JBuilder. And as I said, if I do it outside JBuilder, the next time I compile it is removed since JBuilder doesn't recognize it.
The error I keep getting is that JBuilder cannot find the taglib jar, because I cannot put it where it can find it, and when I reference it as in another directory (c:/cocTags/cocTags.jar) it doesn't understand what protocol "c:" is.
Confused? I am. This cannot be that hard.
So, to help me out, assume only 2 things: 1) cocTags.jar whose TLD is validated, in c:/cocTags/ and 2)a coc project in c:/coc/, with the usual jsp directory structure, especially including WEB-INF.
From that point, step by step in JBuilder, how do I add cocTags.jar to the project so that I can use them?
I love JBuilder, but this is riduculous.
Thank you so much for any help you can offer,
Ian Ohlander
IanOhlander@yahoo.com


Peace favor your sword.<br />May the last embrace of the mother welcome you home.<p>Ian
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
I've not used JBuilder for tag development, but I do know of somebody that tried to do it and also came up against similar problems, where JBuilder just didn't seem to like the whole web application format. :roll:
Needless to say, he reverted back to using ant files. Sorry that didn't really help you!
Simon
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
You need to add your taglib.jar as a required library under project properties. When you build your web app, it will be placed under defaultroot/WEB-INF/lib. You will also have to manually place your .tld file in the WEB-INF directory. That's pretty much it.
HTH
[ June 24, 2002: Message edited by: Jason Menard ]
Ian Ohlander
Greenhorn

Joined: Jun 15, 2002
Posts: 16
Thank you. I will try your suggestion when I can.
I really get the impression that Borland wants you to use their InternetBeans tag library, instead of another. Very frustrating.
Appreciate all your help.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Originally posted by Ian Ohlander:
Thank you. I will try your suggestion when I can.
I really get the impression that Borland wants you to use their InternetBeans tag library, instead of another. Very frustrating.
Appreciate all your help.

Personally I can't stand the InternetBeans tag library. Although I've had to deal with code that has used them, I have never made the choice to implement anything with them myself. Fixing the code that used them, I had to subclass one of their classes just to get the desired behavior from it, which shouldn't have been necessary IMHO.
Anyway, using custom tags with JB6 is really no big deal as you'll find out when you are able to play with it some more. The thing with JBuilder is that you have to remember to add every external library/jar/etc... that you need to your project required libraries. JBuilder libraries are actually rather convenient in my opinion, particularly when working in a team environment. It is a very simple matter to ensure that everybody is using the same version of any given library this way, as well as making it trivial to upgrade a library and have your projects opint to the latest version.
Ian Ohlander
Greenhorn

Joined: Jun 15, 2002
Posts: 16
Ok, I must be dumb or something, because I cannot get this to work.
In JB I created two tags: alphaDisplay and categoryDisplay, both declared as part of package coctags. I initially made my own coctags.tld file, based on those I found in books, and it looked alright (that is to say, it validated properly.) I tried making a jar file with JB, but had problems. So I simply used winzip. I put my two generated classes in a folder, along with another folder, META-INF, with the tld., and zipped it up. Then changed the extension to .jar, added it to the needed libraries of my coc project, and added the coctags.tld to c:/coc/defaultroot/WEB-INF/. Then my tagTest.jsp looked like this:

But I kept getting an error message:
"tagTest.jsp": org.apache.jasper.JasperException: No such tag in the tag library imported with prefix coc

I checked my tld, and it looked exactly how it was supposed to. But I used an openTool taglib generator on the tags and used the following, just in case I made a mistake. Mine was exactly the same, but here it is.

Still get the same error message. I know the library is being used by JB. The structure pane shows that coctags directory and the two tags are part of the project. But still nothing.
I also tried this using just tomcat (in the webapps dir) and no jar file, thinking maybe I was having trouble with the jar. Just a simple tlds directory in WEB-INF with coctags.tld in it. Classes holds a directory called coctags, which has the two compiled classes. I get the same error message.
What am I doing wrong?
Ian Ohlander
Greenhorn

Joined: Jun 15, 2002
Posts: 16
That last part of my post wasn't very clear. I thought maybe the whole .jar deployment process was flawed somewhere, so I tried to do it without a jar, in Tomcat 4.0. I created the appropriate dir in webapps, place my tagTest.jsp in it, also created a WEB-INF/tlds dir and put coctags.tld in that. Then, in webapps/chamberofcommerce I made a classes/coctags dir, and put the two compiled tag classes in that. I modified my tagTest.jsp to get the taglib from /WEB-INF/tlds/. I didn't modify my coctags.tld because it showed the tag classes to be found at coctags.*Display.
So I have:

But, as I said, I still get the same error message. 'No such tag found in taglib coc.'
At this point, I am frustrated because, as far as I can tell, I have set things up properly. But it must be the case that I am missing something, and have been looking at it too long, so that the thing wrong doesn't even register- it looks normal.
Any ideas?
Thanks.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
A couple of things to look at...
(1) Have you defined any mappings in your web.xml file for this tag library?
(2) If not, and if you want to directly access the tag library from your JSP page by a direct location (not really recommended), have you tried using the following taglib directive in your JSP page:

(notice the additional "tlds" bit to match where you have put your TLD file)
Hope that helps...
Simon
[ June 27, 2002: Message edited by: Simon Brown ]
Jignesh Malavia
Author
Ranch Hand

Joined: May 18, 2001
Posts: 81
Hello Ian,
If you want to use the library deployed as a jar, follow this convention and it should work.
1. In the TLD file, use the <uri< element
with any value, say http://ian.com
2. Place the TDL fils in the jar file at META-INF/taglib.tld
(NOTE: Rename cocLib.tld to taglib.tld before jarring. META-INF must be all caps. These two requirements must be satisfied when using jar libraries)
3. Then in the JSP page, use the above mentioned uri. The JSP engine will implicitly create a mapping between the TLD file in the jar and the uri element in the taglib.tld. So no need to explicitly specify the mapping in the web.xml either.
Hope this helps
-j
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Originally posted by Jignesh Malavia:
2. Place the TDL fils in the jar file at META-INF/taglib.tld
(NOTE: Rename cocLib.tld to taglib.tld before jarring. META-INF must be all caps. These two requirements must be satisfied when using jar libraries)

Jignesh is right, and this is a much better way to deploy tag libraries - especially in a production environment. In addition to this though, and since you are using a JSP 1.2 compliant container, you are not constrained to calling the TLD file "taglib.tld".
Actually, since you are using Tomcat 4, you could write your TLD file using the new(er) XML elements.
Simon
Ian Ohlander
Greenhorn

Joined: Jun 15, 2002
Posts: 16
OK, I tried your suggestions. Let me explained how.
First of all, keep in mind that I now have two "projects" (not JBuilder projects, but rather two avenues I am pursuing.)
1. Try to get my taglibs to work in JBuilder using a tag library jar. This involved creating the jar, adding it to the necessary libraries for this project, and adding the tld (in addition to its place in the jar) to /WEB-INF
2. Try to get my taglibs to work period, using just the classes, tlds, and Tomcat 4.0 standalone. This came out of the fact the 1 wasn't happening and I wanted to see if the problem was the jar deployment process. This involved simply putting the tld in WEB-INF/tlds, the *Display.classes in WEB-INF/classes/coctags/, and making sure my JSp referred to the tld properly.
Simon, in 2, I changed the taglib directive to reflect the fact that coctags.tld resided in WEB-INF/tlds/. Still, I get the same error. I was going to use an XML mapping in web.xml, to decouple the talib directly from the jsp, but first I just wanted to make it work. Still nothing, so far. The same error: tag with that name not found in taglib with prefix coc. As I said, my tld looks alright, I think I have the right directory structure, and the taglib directive is getting the coctags.tld. It's just not finding the tag alphDisplay in that tld (or maybe it can't find the class.) But I printed the directory structure. Is the tld referring to the classes properly? Are they in the right place?
Jignesh,
Good suggestion. I didn't know that (in project 1) my jar file had to have the taglib named taglib.tld, as opposed to something else. The META-INF directory is there, but the tld was not named properly. So I changed the name, and I also changed the tld to add the uri element. I simply used "coc". Then in my jsp file, I changed the taglib directive to say:

Naturally, as you can see, I changed my prefix (to avoid any naming complications), so my reference to it later has been changed to:

Finally, I added the uri change to the tld that resided in /WEB-INF (for JBuilder, as suggested above).
In this case, I get the error: "Could not find file /coc".
So, again, in case this was a problem in JBuilder, I added the URI change to the tld in project 2 (the tomcat, JAR-less edition), and made the appropriate changes to the jsp (referring to it as "coc".)
At this point, I have made about 4 or 5 changes, all of them straightforward, and seemingly with little room for mistake. But mistakes there must be, either in the changes or in the original structure. I could understand if project 1 wasn't working. It involves a rather complicated IDE, with necessary libraries, etc. But project 2 should be rather simple. TLD in the appropriate place, classes in the appropriate place, tld referring to classes properly, and jsp referring to the tld properly. As I mentioned, in project 2, the only thing I am usure of is the location of the tag classes themselves. I honestly can't see any other problem. Of course, that doesn't really mean anything.
Thank you all for your help. I really do appreciate it. But does anyone have any ideas?
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6

Is the additional space between coc: and alphaDisplay just a typo? Also, you need close off your custom tag with "/>" (or </coc:alphaDisplay>) .
Simon
[ June 27, 2002: Message edited by: Simon Brown ]
Ian Ohlander
Greenhorn

Joined: Jun 15, 2002
Posts: 16
Thank you so much. I knew it was something I had looked at so long that I didn't even notice.
I owe you guys.
Thanks.
Ian Ohlander
Greenhorn

Joined: Jun 15, 2002
Posts: 16
Well I'm back still with the original problem. As I mentioned in the last post, I was able to get my tags to work. But that was with what had become the 2nd part of my project- just to get them to work in Tomcat as a standalone. With that success (and what looked like some promising leads on the internet, including some openTools) I figured I could get the rest, that it would only be a matter of time and why did I want to bother all the nice people here anyway when I was going to get it any moment.
Hubris, as they say. I am in some serious need of help, here. This is not a project that is time sensitive, except that I just want to get the dang thing to work. I love java programming, got certified as a Java 2 programmer in February, and now and absolutely loving JSP and servlet programming. I want to do this.
But this JBuilder is really starting to get to me. I really have liek using it, but I don't understand why they have to make the process of using custom tags so complicated.
So to those who can help, please, help me.
I have a tag library that I know works- It works when I use it in Tomcat, exactly as I want it to. So assume, now, that I have this library, called coctags.jar (alphaDisplay.class, categoryDisplay.class, META-INF (a directory) and in that, taglib.tld, which has been validated.) Now I wish to use this tag library in a new project. What do I do? What are the steps, pure and simple, to use these tags in this new project in JBuilder 6?
Please, anyone who has used JB this way, help me. I'm dyin' here. This can't be that hard. Otherwise, I'm seriously rethinking my decision to use JB for projects.
Thank you,
Jignesh Malavia
Author
Ranch Hand

Joined: May 18, 2001
Posts: 81
This is what i did on JBuilder 7 with the tag library from jakarta (You can Substitute the directory names and library names according to your requirements.)
Downloaded the datetime library from jakarta and saved as
D:\download\datetime\datetime.jar (from jakarta)
STEP 1
Manually created a new directory D:\PTagTestDir
Using menu->New->New Project, created a new project in JB named named PTagTest
JB automatically created directory named D:\PTagTestDir\PTagTest
---------------------------------------------
STEP 2
Manually created a new directory D:\WTagTestDir
Using JB, menu->New->Web Application in the PTagTest project, created new Web Application named WTagTest.
JB automatically Created D:\WTagTestDir\WEB-INF\web.xml

---------------------------------------------
STEP 3
Menu->Project->Project Properties-> select "Required libraries" tab
click 'Add' button
Will popup 'Select One or more libraries' dialog
Click "New" button
will popup New library wizard
Name : mylibrary
location : User home
Library path : click add and select D:\download\datetime\datetime.jar
click ok
back to previous dialog
select the newly added mylibrary
click ok
back to Project properties dialog

JB automatically created D:\WTagTestDir\WEB-INF\lib
and copied datetime.jar
---------------------------------------------
STEP 4
Click on the web.xml on left upper pane
Click on Tag Libraries left lower pane
on right
use URI = http://www.whatever.com
use URI = /WEB-INF/lib/datetime.jar
---------------------------------------------
STEP 5
File->New->JavaServer Page
In the wizard dialog box
Name hello
Keep the checkbox checked for Create Runtime Config. Named as hello

JB creates the file D:\WTagTestDir\hello.jsp and opens for editing

Add the follwoing lines
<%@ taglib uri="http://www.whatever.com" prefix="test" %>
The curent time is <test:currentTime>
---------------------------------------------
Step 6
Verified the directory structure created by JB

D:\PTagTestDir\PTagTest

D:\WTagTestDir\hello.jsp
D:\WTagTestDir\WEB-INF\web.xml
D:\WTagTestDir\WEB-INF\lib\datetime.jar

---------------------------------------------
STEP 7
Click on Menu-Project-Rebuild Project
Click on Menu-Run-Run Project
"It works on my machine" Hope it works on yours too :-) good luck
-j
[ July 12, 2002: Message edited by: Jignesh Malavia ]
Dane Frazier
Greenhorn

Joined: Jul 15, 2002
Posts: 18
Folks, I have questions as well.
I too am using JB6, and find it useful (having used quite a few, and plain text editors as well).
I've been using JSP / Beans / Servlets for a couple years, but now code is getting like a run-away pasta dish as the complexity and cut and paste increases. So after a bit of reading, re-reading and trying examples, such as those in Ch. 9 of Prof. JSP 2nd ed.; the "hellouser1" example seemed simple enough...
Buuuuutt I can't get the darn thing to go.
I have installed Tomcat 3.3 on my workstation to test independant of the version in JB6.
Both come up with the same error at run time...
org.apache.jasper.compiler.CompileException: C:\work\test\HelloUser1.jsp(7,2) Unable to load class null
Any help is greatly appreciated.
-dane
My "files" were gotten from the Wrox site for "Prof. JSP 2nd Ed.", out of the archive for ch 09 and are as follows:
directory structure for 'tomcat-3_3_1' use:

hellouser1.tld - (note the only difference in the dtd path from the example):

web.xml - no changes:

HelloUser1.jsp:

HelloUser.java: (added exception imports to quiet "can't find xx class errors" by JB6
Ian Ohlander
Greenhorn

Joined: Jun 15, 2002
Posts: 16
Thanks Jignesh. I tried it (exactly what you listed, using datetime.jar, etc, just to make it work) with only a couple differences that I think may be because of the version I am using. Like When creating a JSP, there is no create runtime configuration box, or when creating the project PTagTest in PTagTestDir, the resulting directory structure doesn't match what you listed. Oh, and the new? version of datetime.jar doesn't have a tag called currentTime, but instead something else (can't remember now, but caught it in the tld). But with those minor changes (especially that last) I hoped for success. I followed your steps exactly.
Still same error as before: can't find class ... as I mentioned above. So I uninstalled and reinstalled JB6, and still no dice.
I am going to get Borland's customer support in this since this is getting ridiculous. Unless you can think of something that I haven't done.
Thanks again,
Ian
Ian Ohlander
Greenhorn

Joined: Jun 15, 2002
Posts: 16
Ok, just wanted to give an update for future reference purposes. If anyone else seems to have similar problems with jbuilder and tag libraries, I hope this will help.
As I mentioned above, I got the tag libraries working in just the tomcat standalone server. My goal was then to get a simple tag library to work in jbuilder. I'm still surprised that now that I know how to do it, I still have not been able to find anything in the jbuilder documentation, newsgroups, etc.
I followed Jignesh's suggestions very closely to the letter- with one exception- the DateTime.jar file had been changed. There was no "currentTime" tag. So, and this was the mistake I made that in hindsight is incredibly obvious and indeed, foolish, I used an unzip program to look at the structure of the DateTime.jar and saw a tag named "DateTimeTag.class". So I used that name, "DateTimeTag" for the tag. And I kept getting an error message. Then, one evening a month ago, I was going to sleep and it suddenly occurred to me that another name was probably being mapped to that tag in the tld. No sooner said than checked. And I was right. It is referred to as "DateTime". So it compiled and ran fine.
So now I had a working tag library in JB. That told me that my JB environment was correct and that my procedures were correct. So back to my original problem. I have a tag library called cocTags.jar, with a validated tld and two tags: alphDisplay.class and categoryDisplay.class. I included it as part of a library, set the xml tld descriptor to refer to the tld. I had the proper jar tld structure. And yet I was getting a "no such tag found" error.
Ok, so if I am doing everything correctly, and I followed all the procedural suggestions I could find, especially here, especially that which worked with the other tag library (and that really helped because it gave me a model to look at- I could check what was being done here and there, and when I found no discrepency in the methods, then that left only one plact to look), then my problem must reside in my assumptions. Recall that I said "assume you have a working tag library, with a proper tld."
Therein lay the problem. You see, the tags worked. They worked in the standalone of tomcat, not in an jar form. But now that I was using them as part of a jar, the situation was different. My tld mapping to the tag class and my jar directory structure did not coincide! In other words, it was getting the library, found the tld and went looking for the tag. But an error I had made in the tld and the jar's structure made it unable to find the tag. Of course, that seems like a most basic thing, now. But tracking it down was a pain, mainly because I had a faulty premise, and if you proceed from a faulty premise, then even if your logic (or in this case, procedure) is correct, your outcome will not be what you want.
So here it is: the definitive (and how's that for arrogant. I have problems making the most basic part work. But I mean, in other words, the very clear steps to using tags in JB- or at least how I did it.)
1. Create your tag library- the tag classes
2. Make your tld.
3. Make sure your tld refers to the tag properly.
4. Make sure the tld's reference matches the prospective jar's structure.
For example, if you have the following in your tld:

then alphaDisplay.class should reside in directory called coctags that is in the root of the jar.
On the other hand, if you had:

then alphaDisplay.class should just be in the jar's root. Even though the tag may be part of a package (say coctags), your tld does not have to refer to it as "coctags.alphaDisplay". That was where my problem lay. I kept having it refer to "coctags.alphaDisplay" when alphaDisplay.class was in the jar's root, becasue I thought that since it was part of that package, that was how it had to be.
So bottom line is, make sure the jar structure matches what the tld specifies. And validation will not catch that.
5. Make the jar.
6. In JB, under the project properties/required libraries, either create a new library or use an existing one. If creating one, name it something, and then add the necessary jars to the library.
7. (Optional, but is a best practice) Point your web.xml taglibrary descriptor to the jars (they will be under WEB-INF/lib).
8. add a tag library refernce in your jsp under some name and mapping to either the actual jar file or to the taglibrary descriptor name referred to in the web.xml file.
9. Finally, jut use your tags, making sure to use the proper names that the tld specifies.
And that's it, I think. End of story. I felt dumb, but at the same time glad it was tracked down. I could not have done it without your help, people. That's why I am posting this: so anyone else doing a search on the subject can find something more explicit that what I found, and that also mentions some of the pitfalls and assumptions that can contribute to the error.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JBuilder 6 and custom tag-libraries
 
Similar Threads
JSTL version causing exceptions?
Location of tld files
Tag files inside a JAR.
Enabling JSTL tags
JSTL Error in Weblogic 7.0