• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tag Lib calling a class

 
Tom Piersa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I’ve written a java class that is going to be used by several different application types. It’s all done and it works real well. I wrote a simple java command line application that calls it and it works real well.

I now need to write a tag library that calls the class. A proprietary development tool we use can only call my class from a tag library. The problem I’m having is that when I try to declare an instance of my class I get a compiler error. My class and the tag library are in the same directory. Just like my command line program was.

nypldap onypldap= new nypldap();

tagnypldap.java:21: cannot find symbol
symbol : class nypldap
location: class TagLibs.tagnypldap
nypldap onypldap= new nypldap();
^

I’m guessing there’s something special about compiling a tag library and that I need to tell javac where the class is. But I’m not sure how.

Thanks,

Tom
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without any further information it's going to be hard to help.

(Is your class really named with a lower-case letter?)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing special about compiling a tag library, but just like any other Java compilation, all referenced classes must be in the classpath.

And yes, not following universal Java naming conventions makes your code incredibly hard to read. Strongly suggest you join the fold and name things using the universally accepted conventions.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This little article gives you a big help.
 
Tom Piersa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok -I'll read the article tonight. I'm an old time basic programmer (1978). I've only written a couple of command line java programs. This is my 1st crack at doing somthing that will be reusable. I've been using VB.net naming conventions internally.

You've confirmed that it's most likely somthing real simple. The class, the command line test program that calls the class and the tag lib are all in the same windows folder. The class compiles clean. The command line program compiles and runs fine. I must be doing somthing real simple wrong in the tag lib. I'll look at the code in the Am.

Thanks,

Tom
 
Tom Piersa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK – article read. I’ll start another thread with questions I have about naming conventions. For now, I’m trying to keep the problem at had isolated.

I stared at the one line of code for several hours. Drank lots of coffee and scratched my head lots. I made minor changes. They all failed. In a final act of desperation, I cut the code from the nypldap class, imports and all, and pasted it into my tag library class. So everything was in one file.

It compiled clean !?!?

Question 1 – Why?

(rant and rave)The good news is that I can keep working developing the tag library interface. But this is not what I want. I now have the some code in two places. I want the class kept in one place, one copy, one file. I want to be able to call the same class(nypldap.class) from a command line program (callnyplday.class) and a tag library (tagnypldap). There are most likely other java interfaces that I can also use to call this class, like a servlet. I want to maintain one(1) copy of the source for nypldap.java that I can maintain in one place.

The first line of my tag lib is:
Package TagLibs;

Question 2 – Does this limit where javac looks for class files?

thanks again,

Tom
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is likely in your compile-time classpath. The fact that your class is a tag handler is completely moot to the compiler.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hopefully the capital "P" is a typo. In general, packages shouldn't start with a capital letter, btw.

Without knowing anything else about the code or your class hierarchy, I'd have to agree with Bear--it's likely you're compiling it incorrectly somehow.
 
Tom Piersa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way I'm compiling it is:
javac tagnypldap.java

Should I have the the class nypldap some place on the command line?

nypldap.class and tagnypldap.java are in the same directory.

Thanks,

Tom
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point, I'm moving this to Beginning Java as it seems to be a simple compilation issue.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Piersa wrote:
javac tagnypldap.java

Should I have the the class nypldap some place on the command line?

nypldap.class and tagnypldap.java are in the same directory.


as mentors and other rancher already suggested you about writing a right way coding in java, but you're still not using it, I am afraid that you're making
your task difficult.


 
Campbell Ritchie
Sheriff
Pie
Posts: 48935
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

You have already been told about capitalisation conventions; they are there for a reason. Do your .java files have a package name declared anywhere?
 
Tom Piersa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I do have a package statement. It's the very first line of the program.

package TagLibs;

Yes, I know the name of the package is evil and horrible. I'm working off another teaching site that used it in an example in an artical. I learned alot from the site. Nameing conventions was not one of them. I will write them and tell them that they are evil and horrible and their site should be shutdown and domain name revolked over the weekend.

As far as the naming thing goes. I deal with one problem at a time. Once the compile issue is resolved. I will address the nameing issue. That's the priorities.


Tom
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why you're not giving all the information we need to help solve the problem :/

How are you setting the compilation classpath?

We're giving you grief about the naming conventions because it *really* throws people off when they're not followed--and since you can't compile anyway, it seems like a good time to bring them in line with the other 99% of the world :)
 
Stefan Evans
Bartender
Posts: 1715
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to specify a classpath root where java should go looking for related/imported classes.
By default the classpath is the current directory

Two possible solutions
Go to the root level of your package structure and:



or from the directory with tagnypldap.java in it:


Alternative #3: Use an IDE like Eclipse/Netbeans, which takes care of that stuff for you
 
Campbell Ritchie
Sheriff
Pie
Posts: 48935
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you calling the compiler? Which order are you compiling your .java files in? If you don't use package names, you simply compile the .java file with the main method in, and the javac tool finds all the other files automatically. If you have package names, however, the javac tool operates on the assumption that the other files have already been compiled; if it can't find a .class file it will throw an error.
Needless to say, this is a common problem; look at this post of mine from last year and the links in it. You will doubtless find more information if you search this forum for "compile package" and "compiling package".
 
Tom Piersa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The idea that I’m doing something wrong while trying to compile has occurred to me. This last round of posts really gives me a lot to work with. The way I’m compiling the class is:

javac nypldap.java

The way I’m compiling the tag library is:

javac tagnypldap.java

I also have a command line program that calls the class nypldap.java. It’s working fine. I compile it like so:

javac callnypldap.java

I’ll try the compile options mentioned.

Thanks for the help,

Tom
 
Campbell Ritchie
Sheriff
Pie
Posts: 48935
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless you are moving from directory to directory between those two compiler calls, that is probably not going to work. See whether the old links I quoted work; if not, please ask again.
 
Tom Piersa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you soooooo much Cambell. Real, real simple solution:

javac tagnypldap.java nypldap.java

And it even worked with those horrible, evil tag and class names 

Problem solved. Will start another thread with questions on the dangers of using horrible and evil names.

Thanks all, It’s only a job,

Tom
 
Campbell Ritchie
Sheriff
Pie
Posts: 48935
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Piersa wrote: . . . Will start another thread with questions on the dangers of using horrible and evil names. . . .
We'll all refuse to read it

And . . . you're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic