Solved

Tomcat 4.0.2 - Class loading problem.

Posted on 2002-07-12
22
189 Views
Last Modified: 2013-11-24
Hi folks.

Tomcat is Java related, I think this is the best place for this question.. If not let me know.

Ive just installed Tomcat, which is nice.  Examples are all working, im running through port 80, nice nice nice, got my new test app working, nicer.

When i try to import a class however, one that is common across all apps and resides in d:\classes, (which in turn is in my classpath) it breaks !

I have looked at the docs. Apparently Tomcat does not look in the System classpath by default. By default Tomcat looks in the following for classloading ( this is from the site )

/WEB-INF/classes of your web application
/WEB-INF/lib/*.jar of your web application
Bootstrap classes of your JVM
System class loader classses (described above)
$CATALINA_HOME/common/classes
$CATALINA_HOME/common/lib/*.jar
$CATALINA_HOME/classes
$CATALINA_HOME/lib/*.jar

So, i put all of my d:\classes in $CATALINA_HOME/common/classes .. i expected my app to pick these classes up, but it does not and i still get a NoClassDefFoundError on the class my app trys to get hold of.

So, i need to know why i cant get these common classes to be visible to Tomcat when they should be.

As an interesting side note (this may be related) my helloworld servlet in a new app i created works by using the servlet class name :

http://localhost/cms/servlet/HelloWorld

However I cant use the web.xml of my application to call it something else.. ie :

<servlet>
    <servlet-name>Choochoo</servlet-name>
    <servlet-class>HelloWorld</servlet-class>
  </servlet>

http://localhost/cms/servlet/Choochoo does not work ! Looks as though maybe my application is not set up correctly, could that be causing this ?

lots of info there, any help would be appreciated.

Mucho thankios.

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker
0
Comment
Question by:mehdi
  • 12
  • 4
  • 4
  • +1
22 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 7148588
 Try to put the class under your WEB-INF/classes folder of your web application. It should pick it up immediately. At least that's how the non-Catalina Tomact versions work. I am not very familiar with Catalina but it is worth trying it.

  Hope it helps.
0
 
LVL 1

Author Comment

by:mehdi
ID: 7148614
That does work. Classes are picked up from the WEB-INF/classes directory (otherwise my servlets would not have worked either)

i can get it to work that way, but that would mean duplicating a whole bunch of common classes across different applications.  I really need to put the common classes in a completely seperate place *and* have them being picked up.

any ideas ?
0
 
LVL 35

Expert Comment

by:girionis
ID: 7148626
 Ok I see what you mean. Try to put them  under the $CATALINA_HOME/classes folderand see what happens. If this still does not work then try to put all your common classes into a jar file and put this jar file udner the $CATALINA_HOME/lib folder. If things still do not work try to restart the server. You never know.

  Hope it helps.
0
 
LVL 1

Author Comment

by:mehdi
ID: 7148640
I have put everything into CATALINA_HOME/classes (not jarred).

This should work, i dont see what could be going wrong, except that possibly, my application is not set up correctly in server.xml and is subsequently cut off from the common classes...  This may also explain why I cant override the servlet name in my apps web.xml.  This is what i added to my server.xml for my application :

<Context path="/cms" docBase="d:\webcontainer\mehdi_cms" debug="0" reloadable="true" crossContext="true" appBase="webapp" />

am i missing something basic like pleaseWork="true" ?

Grr

Cheers,

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker
0
 
LVL 35

Expert Comment

by:girionis
ID: 7148674
 Since you can run the classes properly from the WEB-INF/classes I would say that there is nothing wrong with your web app. DIdi you restart the server? Did you try to pack the classes and put htem under CATALINA_HOME\lib?
0
 
LVL 1

Author Comment

by:mehdi
ID: 7148688
I have restarted several times, to no avail.

Im not interested in jarring the classes up, id like them to be picked up unzipped from /common/classes.

Cheers,

0
 
LVL 35

Expert Comment

by:girionis
ID: 7148729
 Sorry.. I have not got any other ideas. The specs say that you put them into CATALINA\classes.. Maybe there is something wrong with your web app. Try to define a brand new one. And you should at least try to jar them up and put them in the \lib folder, just for testing purposes. It might give you some clues.

 
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7148761
I haven't used tomcat lately, but you can always modify (check) tomcat startup .bat/.sh file
0
 
LVL 1

Author Comment

by:mehdi
ID: 7148774
..heyhey

yeah, ive been looking at that possibility - catalina.bat is the one to change, and its probably a small change but still makes my eyes go crossed :[

I would however like to know why the $CATELINA_HOME/common/classes is not being used to load common classes.... this is meant to be a basic feature and im a little worried why its not working for me...

reboot.

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker
0
 
LVL 1

Author Comment

by:mehdi
ID: 7148779
girionis..

your right will definately be testing this.

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 7148792
> The secret lemonade drinker


but why 'secret' ?
is that outlawed in your country ? :)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Accepted Solution

by:
rrz earned 185 total points
ID: 7149991
First,about your side note  
Did you add a  <servlet-mapping> ?  
If, you did something like the following
 <servlet>
   <servlet-name>Choochoo</servlet-name>
   <servlet-class>HelloWorld</servlet-class>
 </servlet>
 <servlet-mapping>
   <servlet-name>Choochoo</servlet-name>
   <url-pattern>/Choochoo</url-pattern>
 </servlet-mapping>
and if you changed the port to 80
then you access with  
http://localhost/cms/Choochoo
if left the default port then use http://localhost:8080/cms/Choochoo  

For your main question,  
Did you try the simpler way? You could try to deploy your context without making a entry in server.xml by putting your context in the webapps directory. Please see if  Tomcat can find your common classes  with your context configured this way.

0
 
LVL 1

Author Comment

by:mehdi
ID: 7153810
heyhey

the secret lemonade drinker was an Advertising campaign for a brand of lemonade called r-whites - The worlds best advert, for the workds best lemonade :

http://www.necrosdomain.co.uk/downloads/tvthemes/rwhites.ra

- I was young and impressionable when that ad came out.

rrz

I am going to try your sugestions now.

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker
0
 
LVL 1

Author Comment

by:mehdi
ID: 7153882
rrz, i did the servlet-mapping , this works fine.

I will try just making a project directory in the default webapps directory to try and fix the main problem.

Thanks,

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker
0
 
LVL 1

Author Comment

by:mehdi
ID: 7153923
Guys,

This is what i tried to do.  I put a jsp in an existing webapp (/examples).. ie :

\webapps\examples\jsp\dates\med.jsp

This is the code in the jsp :

<html>
<body>
<%
org.apache.velocity.servlet.VelocityServlet v = new org.apache.velocity.servlet.VelocityServlet();
out.print ("ok");
%>
</body>
</html>

i ran it :

http://localhost/examples/jsp/dates/med.jsp

and i got a couple of error messages one was :

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.


and the other more to do with the problem at hand i think, was :

Generated servlet error:
D:\apache_tomcat\work\localhost\examples\jsp\dates\med$jsp.java:59: Class org.apache.velocity.servlet.VelocityServlet not found.
                org.apache.velocity.servlet.VelocityServlet v = new org.apache.velocity.servlet.VelocityServlet();

Thanks,

Mehdi

0
 
LVL 27

Expert Comment

by:rrz
ID: 7154370
The first message is a warning. Look at the bottom of the following page  http://java.sun.com/webservices/docs/ea2/tomcat/ReleaseNotes.html  
I don't use Velocity but I assume that it is your common class.  Please tell us where you put it.
0
 
LVL 1

Author Comment

by:mehdi
ID: 7154428
i put velocity in common/classes/org.... etc, its one of the bunch of classes that would be ideal as a "general" group of classes for cross app development.

I think i may have found something out !  One of the packages that i had placed in common/classes (com.sun) may have been intefering with CATALINA.  Removing this package has given me slightly different results.. I will let you know how this goes.

cheers,
sld
0
 
LVL 1

Author Comment

by:mehdi
ID: 7157040
Yipee doo !

Ok, what i did was to put packages into .../common/classes one by one, and test the outcome, rather than to copy the entire lot of classes into this directory.

Like I said in my previose posting the package com.sun seemed to be the main culprit.  When i removed that package things started working.  These are the folders under com.sun :

activation
corba
image
java
jndi
mail
media
medialib
naming
org
rmi

Any ideas on what might be happening ? could one of these packages be taking priority over some catelina classes ?

"Common: contains additional classes that are made visible to both Tomcat internal classes and to all web applications "

so maybe that was the case.

Any thoughtful last words ?

Thanks

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker
0
 
LVL 1

Author Comment

by:mehdi
ID: 7158946
for your reference, some classes under javax also caused the same error.

Anyway, as this seems to have been solved points time..

points go to rzz for answering my secondary problem servlet-mapping.

Thanks for your help guys :)

mucho appreciado indeedo

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker
0
 
LVL 27

Expert Comment

by:rrz
ID: 7159534
medhi, thanks for the points, but I am curious as to why you were trying to use the com.sun package in the first place.
0
 
LVL 1

Author Comment

by:mehdi
ID: 7159564
com.sun.something and some classes in javax too.  These were just in my old classpath.  I just copied my entire classpath (indiscriminately) into somewhere they would be available *if* they were ever needed (common/classes).. I didnt need every one of them by any means - i just never anticipated a problem with having them there...

If you have any ideas as to what the conflict may have been, i would appreciate a clue..

Cheers

~~~~~~~~~~~~~~~~~~~~~~~~~~~
The secret lemonade drinker
0
 
LVL 27

Expert Comment

by:rrz
ID: 7161031
Look at this page  
yourTomcathome\webapps\tomcat-docs\class-loader-howto.html
I am not an expert but I do have an idea to explain the conflict. It would seem to me that Tomcat checks its own first.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now