Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to access com/mycompany/classlib/myclass.class

Status
Not open for further replies.

wgcs

Programmer
Mar 31, 2002
2,056
EC
I've been progressing rapidly: I now have servlets working on my (hosted) webserver, and my classes (in /servlets) can access any classes in the /servlets directory.

Now, before things become too messy, I'd like to be able to create libraries of classes (and use other's libraries).

I understand that I can't just add .JAR files to the CLASSPATH (that can only be done by the administrators of our web host), but I think I should be able to place utility .class files in a subdirectory hierarchy, such as:
Code:
/servlets/com/mycompany/classlib/myclass.class[/cod]
and then:
[code]imports com.mycompany.classlib.*
and I should then be able to use all "myclass" (and all other classes in that directory).

However, I have a simple .java servlet (say, TestUtil.java/.class), that tries to do this. If I place the utility .class files, compiled WITHOUT the "package com.mycompany.classlib" at the beginning, into the /servlets directory, it works fine.

If I, instead, put the "package" statements in, place the utility .class files into the subdir, and compile them there, then put them in that subdir on the server, and delete the duplicate .class files out of /servlets, the server returns "Internal Server Error" when I try to access TestUtil.

What am I missing?
 
Maybe this is too obvious, but have you imported the package in the servlet?
 
Yes, I do have the statement:

imports com.mycompany.classlib.*

in the servlet code; What's strange is that I just expanded a .JAR file and placed the resulting directory tree into \servlets\ and I CAN import the class files in those directories. ( I had to try it this way since I don't have access to change the CLASSPATH ).

So I think there must be something wrong with the method I was using to create the classes/packages in the directory tree.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top