DB Connection without jar in common/lib

I

iksrazal

I'm having a discussion with a group of programmers who are convinced,
unfortunately, that it is possible get a Connection with Tomcat with
the DB driver jar placed in WEB-INF/lib . There motive is they only
want to distribute the WAR. I'm not asking about another alternative,
just if this is possible.

Of course, they get

ava.lang.ClassNotFoundException: com.mysql.jdbc.Driver

with:

Class.forName(drive);
Connection con = DriverManager.getConnection(url,user,password);

I'm invloved trying to find a solution, and a curiosity if some
classloader magic may ber able to solve it.


iksrazal
 
O

Oscar kind

iksrazal said:
I'm having a discussion with a group of programmers who are convinced,
unfortunately, that it is possible get a Connection with Tomcat with
the DB driver jar placed in WEB-INF/lib . There motive is they only
want to distribute the WAR. I'm not asking about another alternative,
just if this is possible.

Of course, they get

ava.lang.ClassNotFoundException: com.mysql.jdbc.Driver

with:

Class.forName(drive);
Connection con = DriverManager.getConnection(url,user,password);

I'm invloved trying to find a solution, and a curiosity if some
classloader magic may ber able to solve it.

Within the application, this should work. Are the driver .jar files in the
WEB-INF/lib directory incomplete or corrupted?

Where is the code located? In a servlet?
 
J

John C. Bollinger

iksrazal said:
I'm having a discussion with a group of programmers who are convinced,
unfortunately, that it is possible get a Connection with Tomcat with
the DB driver jar placed in WEB-INF/lib . There motive is they only
want to distribute the WAR. I'm not asking about another alternative,
just if this is possible.

It should be possible. WARs are intended to support that sort of thing;
it's one of their strengths. They form a single distribution unit that
encompasses a whole webapp.
Of course, they get

ava.lang.ClassNotFoundException: com.mysql.jdbc.Driver

with:

Class.forName(drive);
Connection con = DriverManager.getConnection(url,user,password);

I don't see the "of course" part of that. Placing a jar into
WEB-INF/lib makes the classes it contains accessible within the classes
of the associated webapp, which include servlets, translated JSPs,
filters, tag handlers, and custom classes also included in WEB-INF/lib
or WEB-INF/classes. That is the *purpose* of WEB-INF/lib.
I'm invloved trying to find a solution, and a curiosity if some
classloader magic may ber able to solve it.

No magic should be necessary. Check that the right jar is in
WEB-INF/lib, and that it contains a class with the specified FQ name.
If that doesn't work, try try the webapp on a clean Tomcat install.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top