From: Lew on
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.
>

That's "WEB-INF/lib".

Did you misspell it that way in your actual project?

>>>> When I move the Class.forname [sic] 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.
>

JSPs *are* servlets.

Arne Vajhøj wrote:
> Exact exception text?
>
> Listing of content of webapps/yourwebapp?

You should answer Arne's questions. For one thing, if there was a
build problem and your JAR didn't copy properly to the "WEB-INF/lib/"
directory, you could have a problem.

Consider providing an SSCCE. Talking around your problem doesn't give
enough information to really draw conclusions or provide advice.
<http://sscce.org/>

Just out of curiosity, why are you stuck on such an obsolete version
of Java?

--
Lew
From: Lew on
Pif wrote:
>>>> 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 [sic] folder.
>

Arne Vajhøj wrote:
> Exact exception text?
>
> Listing of content of webapps/yourwebapp?
>

Also, what is the exception's cause ('getCause()') and its (exact)
message?

From the Javadocs for 'ClassNotFoundException':
'The "optional exception that was raised while loading the class" that
may be provided at construction time ... may be accessed via the
Throwable.getCause() method ..."'

--
Lew
Note the two different meanings of the word "may" in that quote from
the Javadocs.
From: Alessio Stalla on
On 9 Giu, 14:27, Lew <no...(a)lewscanon.com> wrote:
> 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.

OK, thanks. I wasn't 100% sure and, yes - I was lazy and I didn't look
it up :)

Alessio
From: Mike Schilling on


"Alessio Stalla" <alessiostalla(a)gmail.com> wrote in message
news:7de01547-d88d-4c26-8932-6be63d419927(a)u7g2000yqm.googlegroups.com...
> On 9 Giu, 14:27, Lew <no...(a)lewscanon.com> wrote:
>> 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.
>
> OK, thanks. I wasn't 100% sure and, yes - I was lazy and I didn't look
> it up :)


But, terminology aside, you are mistaken. See my previous post.

From: Alessio Stalla on
On Jun 10, 4:23 am, "Mike Schilling" <mscottschill...(a)hotmail.com>
wrote:
> "Alessio Stalla" <alessiosta...(a)gmail.com> wrote in message
>
> news:7de01547-d88d-4c26-8932-6be63d419927(a)u7g2000yqm.googlegroups.com...
>
> > On 9 Giu, 14:27, Lew <no...(a)lewscanon.com> wrote:
> >> 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.
>
> > OK, thanks. I wasn't 100% sure and, yes - I was lazy and I didn't look
> > it up :)
>
> But, terminology aside, you are mistaken.  See my previous post.

Right. I tried it myself, too. I suspect it's a compiler optimization
that removes the local variable altogether because it's never used.
Although the compiler seems pretty smart - even with

B b = (1 == (0 + 1)) ? null : new B();
if(b == null) { ... }

there's no trace of B in the bytecode. So, I stand corrected.

Cheers,
Alessio