Craig, 

Thanks again for the information. 
The info. you've supplied has been very useful. 
However, my problem remains: 

I cannot access the class that resides in a JAR file (utilities.jar) in 
<tomcat_home>/shared/lib and get a java.lang.NoClassDefFoundError 

I am spinning my wheels on this so hopefully some details will shed some light on my 
problem. I wrote a very simple servlet that attempts to use the class in the shared 
dir. 

---- 
import com.myco.utilities.CASDate; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

public class Test1 extends HttpServlet { 
// 
public void doGet(HttpServletRequest request, HttpServletResponse response) throws 
javax.servlet.ServletException, java.io.IOException { 

System.out.println("GET method of Test1 invloked"); 
performTask(request, response); 
} 
// 
public void doPost(HttpServletRequest request, HttpServletResponse response) throws 
javax.servlet.ServletException, java.io.IOException { 

System.out.println("POST method of Test1 invloked"); 
performTask(request, response); 
} 
/** 
* Test the use of a shared class. 
*/ 
public void performTask(HttpServletRequest request, HttpServletResponse response) { 

try { 
java.io.PrintWriter pw = response.getWriter(); 
CASDate today = new CASDate(); 
pw.println("CASDate today is " + today.toString()); 
pw.println("CASDate class loaded..."); 
} 
catch(Throwable theException) { 
System.out.println("Error..."); 
theException.printStackTrace(System.out); 
} 
} 
} 
---- 
This is the utility class (some getXXX methods deleted for brevity): 
---- 
package com.myco.utilities; 

import java.util.Calendar; 
import java.util.GregorianCalendar; 

public class CASDate { 
private int ccc = 0; 
private int yyy = 0; 
private int mmm = 0; 
private int ddd = 0; 
private int time = 0; 
/** 
* Default constructor is to create CAS date using the current date. 
*/ 
public CASDate() { 
super(); 
GregorianCalendar cal = new GregorianCalendar(); 
ccc = 20; 
yyy = cal.get(Calendar.YEAR) - 2000; 
mmm = cal.get(Calendar.MONTH) + 1; 
ddd = cal.get(Calendar.DAY_OF_MONTH); 
} 
/** 
* Return a string in MM/DD/CCYY format. 
*/ 
public String toString() { 
String returnValue = getMonth() + "/" + getDay() + "/" + getYearAndCentury(); 
return returnValue; 
} 
} 
---- 

The error I get is: 
java.lang.NoClassDefFoundError: com/myco/utilities/CASDate 

When I moved utilities.jar to <webapp>/WEB-INF/lib the error goes away. 
I hope this provides some clues as to what is going wrong. At this point it looks like 
a bug but I hope I'm wrong. I am using Tomcat 4.1.18.

Any help is GREATLY appreciated. 

Thanks, 
Todd 


-----Original Message----- 
From: "Craig R. McClanahan"<[EMAIL PROTECTED]> 
To: "Pat McGroin"<[EMAIL PROTECTED]> 
Date: Thu Mar 27 13:53:24 PST 2003 
Subject: Re: shared resources 

> 
> 
>On Thu, 27 Mar 2003, Pat McGroin wrote: 
> 
>> Date: Thu, 27 Mar 2003 12:57:03 -0800 (PST) 
>> From: Pat McGroin <[EMAIL PROTECTED]> 
>> To: Craig R. McClanahan <[EMAIL PROTECTED]> 
>> Subject: Re: Re: shared resources 
>> 
>> Craig, 
>> 
>> Thanks very much for the detailed reply. 
>> That is very useful information for getting at resource files. 
>> However, my problem is much simpler. I am simply getting 
>> java.lang.NoClassDefFoundError errors when I try to use classes in JAR files in the 
>> <tomcat_home>/shared/lib directory. 
>> When I move the jar files to my <webapp root>/WEB-INF/lib the classes are loaded 
>> just fine and I don't see these errors. 
>> 
> 
>One likely cause for this sort of thing: if a class in your "problem 
>child" JAR file is itself loaded from the shared class loader, but tries 
>to access a different class that is in the webapp class loader, you'll get 
>exactly this sort of problem. 
> 
>Note that NoClassDefFound errors do *not* say that the class named in the 
>exception report cannot be found (that would be a ClassNotFoundException). 
>Instead, it means that one of the classes that this class depends on 
>cannot be found. 
> 
>> Thanks, 
>> Todd 
> 
>Craig 
> 
>> 
>> 
>> -----Original Message----- 
>> From: "Craig R. McClanahan"<[EMAIL PROTECTED]> 
>> To: "Tomcat Users List"<[EMAIL PROTECTED]> 
>> Date: Thu Mar 27 12:33:57 PST 2003 
>> Subject: Re: shared resources 
>> 
>> > 
>> > 
>> >On Thu, 27 Mar 2003, Pat McGroin wrote: 
>> > 
>> >> Date: Thu, 27 Mar 2003 11:20:49 -0800 (PST) 
>> >> From: Pat McGroin <[EMAIL PROTECTED]> 
>> >> Reply-To: Tomcat Users List <[EMAIL PROTECTED]> 
>> >> To: [EMAIL PROTECTED] 
>> >> Subject: shared resources 
>> >> 
>> >> Hello. 
>> >> 
>> >> I am trying to reference a few JAR files from an out-of-process Tomcat 
>> >> 4.1.18 application. 
>> >> 
>> >> The Tomcat 4.1 documentation says that unpacked shared classes and 
>> >> resources will be loaded out of the <tomcat_root>/shared/classes 
>> >> directory and packed shared resources are loaded out of 
>> >> <tomcat_root>/shared/lib: 
>> >> 
>> >> http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html 
>> >> 
>> >> I put a few JAR files in <tomcat_root>/shared/lib but they are never 
>> >> loaded. I can move them into my <webapp root>/WEB-INF/lib and they are 
>> >> loaded without problems. 
>> >> 
>> >> Am I misunderstanding how resources are found in Tomcat 4.1? The 
>> >> context I am using is not within <tomcat_home>/webapps. It is in an 
>> >> entirely diferent directory. Could that be the problem? 
>> >> 
>> >> I posted a simliar question a few days ago but was not yet properly 
>> >> subscribed so I apologize for the duplication. 
>> >> 
>> >> Thanks in advance for any help! 
>> >> 
>> > 
>> >When accessing resources with getResource()/getResourceAsStream(), it is 
>> >important to remember that there are two different implementations of 
>> >these things, which operate quite differently: 
>> > 
>> >ServletContext.getResource() and ServletContext.getResourceAsStream(): 
>> >* Can be used to access static resources within your web application 
>> >* Resources is specified as a context-relative URI starting with "/" 
>> >* For example, to read the web.xml file as a resource, you would use 
>> > a resource path of "/WEB-INF/web.xml" 
>> >* It doesn't matter whether your webapp is running from an unpacked 
>> > directory or a WAR file, or where the directory/WAR is actually 
>> > located. 
>> > 
>> >ClassLoader.getResource() and ClassLoader.getResourceAsStream(): 
>> >* Can be used to access resources embedded within the class loader 
>> > (or class loader hierarchy) 
>> >* For a standalone app, that means somewhere on your classpath 
>> >* For a webapp installed in Tomcat 4.1, and assuming you're starting 
>> > with the webapp class loader, it checks there and up the hierarchy 
>> > as described in the Tomcat documentation. 
>> >* Resource path must match the directory or package structure of 
>> > the resource to be retrieved. 
>> >* Resource resolution works just like class loading resolution in 
>> > terms of which class loader is searched first. 
>> > 
>> >To access a resource from a JAR file in shared/lib, then, you will want to 
>> >make sure you're using the second kind of resource retrieval methods. 
>> >After getting the right methods called, the next most common problem is 
>> >getting your resource path to match the nested directory structure within 
>> >whatever JAR file is holding the resource. 
>> > 
>> >Craig


___________________________________________________
GO.com Mail                                    
Get Your Free, Private E-mail at http://mail.go.com



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to