Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > tomcat classloader

Reply
Thread Tools

tomcat classloader

 
 
Pif - 34
Guest
Posts: n/a
 
      06-03-2010
Hello, I encounter a ClassNotFoundException when loading Oracle driver
in a servlet (Tomcat 5.5 JDK1.4.2). But my JAR is well placed in the
WEBINF/lib folder.

When I move the Class.forname from my servlet to a JSP page (wich calls
the JSP this works perfectly.

So Tomcat seems to have class loader in servlet or JSP that is different.

Can somebody help me ?

Thanks a lot.
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      06-03-2010
On 03-06-2010 17:29, Pif - 34 wrote:
> Hello, I encounter a ClassNotFoundException when loading Oracle driver
> in a servlet (Tomcat 5.5 JDK1.4.2). But my JAR is well placed in the
> WEBINF/lib folder.
>
> When I move the Class.forname from my servlet to a JSP page (wich calls
> the JSP this works perfectly.
>
> So Tomcat seems to have class loader in servlet or JSP that is different.
>
> Can somebody help me ?


It should work with servlet as well.

Did you by any chance copy the JDBC driver jar file to WEB-INF/lib
after starting the web app?

Arne
 
Reply With Quote
 
 
 
 
Pif
Guest
Posts: n/a
 
      06-04-2010
On 4 juin, 00:22, Arne Vajh°j <(E-Mail Removed)> wrote:
> On 03-06-2010 17:29, Pif - 34 wrote:
>
> > Hello, I encounter a ClassNotFoundException when loading Oracle driver
> > in a servlet (Tomcat 5.5 JDK1.4.2). But my JAR is well placed in the
> > WEBINF/lib folder.

>
> > When I move the Class.forname from my servlet to a JSP page (wich calls
> > the JSP this works perfectly.

>
> > So Tomcat seems to have class loader in servlet or JSP that is different.

>
> > Can somebody help me ?

>
> It should work with servlet as well.
>
> Did you by any chance copy the JDBC driver jar file to WEB-INF/lib
> after starting the web app?
>
> Arne


I don't understand also. I've restarted tomcat several times after
copying the file.
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      06-04-2010
On 04-06-2010 06:07, Pif wrote:
> On 4 juin, 00:22, Arne Vajh°j<(E-Mail Removed)> wrote:
>> On 03-06-2010 17:29, Pif - 34 wrote:
>>> Hello, I encounter a ClassNotFoundException when loading Oracle driver
>>> in a servlet (Tomcat 5.5 JDK1.4.2). But my JAR is well placed in the
>>> WEBINF/lib folder.

>>
>>> When I move the Class.forname from my servlet to a JSP page (wich calls
>>> the JSP this works perfectly.

>>
>>> So Tomcat seems to have class loader in servlet or JSP that is different.

>>
>>> Can somebody help me ?

>>
>> It should work with servlet as well.
>>
>> Did you by any chance copy the JDBC driver jar file to WEB-INF/lib
>> after starting the web app?

>
> I don't understand also. I've restarted tomcat several times after
> copying the file.


Exact exception text?

Listing of content of webapps/yourwebapp?

Arne
 
Reply With Quote
 
Pif - 34
Guest
Posts: n/a
 
      06-05-2010
I've replaced " Class.forName("oracle.jdbc.driver.OracleDriver"); "
by oracle.jdbc.driver.OracleDriver oracleDriver = null;

and this works perfectly. So my Jar is well placed, this seems to be an
error with the ClassLoader of tomcat !?

Arne Vajh°j wrote:

> Exact exception text?
>
> Listing of content of webapps/yourwebapp?
>
> Arne

 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      06-09-2010
"Pif - 34" <(E-Mail Removed)> wrote in message
news:4c0ab15e$0$32742$(E-Mail Removed)...
> I've replaced " Class.forName("oracle.jdbc.driver.OracleDriver"); "
> by oracle.jdbc.driver.OracleDriver oracleDriver = null;
>
> and this works perfectly. So my Jar is well placed, this seems to be an
> error with the ClassLoader of tomcat !?


If that's a local variable, I'm not sure it causes the class to be loaded.

 
Reply With Quote
 
Alessio Stalla
Guest
Posts: n/a
 
      06-09-2010
On Jun 9, 5:05*am, "Mike Schilling" <(E-Mail Removed)>
wrote:
> "Pif - 34" <(E-Mail Removed)> wrote in messagenews:4c0ab15e$0$32742$(E-Mail Removed) ...
>
> > I've replaced " *Class.forName("oracle.jdbc.driver.OracleDriver"); "
> > by oracle.jdbc.driver.OracleDriver oracleDriver = null;

>
> > and this works perfectly. So my Jar is well placed, this seems to be an
> > error with the ClassLoader of tomcat !?

>
> If that's a local variable, I'm not sure it causes the class to be loaded..


If I'm not mistaken, the class should be loaded because it's
referenced in the constant pool, but it will be "initialized" only
when you access it in some way (create an instance, access a static
member). "Initialized" is not the correct term, by that I mean that
static code blocks are executed and static fields are initialized.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      06-09-2010
Alessio Stalla wrote:
> If I'm not mistaken, the class should be loaded because it's
> referenced in the constant pool, but it will be "initialized" only
> when you access it in some way (create an instance, access a static
> member). "Initialized" is not the correct term, by that I mean that
> static code blocks are executed and static fields are initialized.


You're not mistaken and "initialized" is the correct term.

--
Lew
 
Reply With Quote
 
Mike Schilling
Guest
Posts: n/a
 
      06-09-2010


"Alessio Stalla" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Jun 9, 5:05 am, "Mike Schilling" <(E-Mail Removed)>
> wrote:
>> "Pif - 34" <(E-Mail Removed)> wrote in
>> messagenews:4c0ab15e$0$32742$(E-Mail Removed) ...
>>
>> > I've replaced " Class.forName("oracle.jdbc.driver.OracleDriver"); "
>> > by oracle.jdbc.driver.OracleDriver oracleDriver = null;

>>
>> > and this works perfectly. So my Jar is well placed, this seems to be an
>> > error with the ClassLoader of tomcat !?

>>
>> If that's a local variable, I'm not sure it causes the class to be
>> loaded.

>
> If I'm not mistaken, the class should be loaded because it's
> referenced in the constant pool, but it will be "initialized" only
> when you access it in some way (create an instance, access a static
> member). "Initialized" is not the correct term, by that I mean that
> static code blocks are executed and static fields are initialized.


I just tried it.

A.java

class A
{
public static void main(String[] arrs)
{
B b = null;
System.out.println("Hello, world");
}
}

Runs fine after deleting B.class

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      06-09-2010
"Pif - 34" wrote:
>>>> I've replaced " *Class.forName("oracle.jdbc.driver.OracleDriver"); "
>>>> by oracle.jdbc.driver.OracleDriver oracleDriver = null;
>>>>
>>>> and this works perfectly. So my Jar is well placed, this seems to be an
>>>> error with the ClassLoader of tomcat !?

>


Whatever the problem is, it's not an error with Tomcat's classloader.

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tomcat classloader Moiristo Java 0 06-21-2006 02:26 PM
Tomcat classloader problem Mark F Java 0 03-05-2004 02:33 PM
Tomcat ClassLoader/Compile nightmare Mikito Harakiri Java 0 11-06-2003 11:10 PM
ClassLoader + tomcat read-the-signature@send-spam-to-dev-null.com Java 5 07-15-2003 01:28 PM
classloader in tomcat Mr. Miguel Java 2 07-14-2003 06:18 PM



Advertisments