Skip to main content

Where to put libraries ??

3 replies [Last post]
asantiago
Offline
Joined: 2006-11-09

Hi all,

I have a GF2 server with some EJB modules that requires JDBC resources that uses postgres drivers. Then I have copied the postgres drives into the "domain1/lib" dir.

Now I have JAR library package E which works as my "data layer" using JPA to persist and query. This package need another postgres driver. Also, this package is used by a web application A.

When I deploy the web application A in the server I was copied the postgres driver required by the package E in the "domain1/lib/applibs".

The problem is that I get a "no suitable driver found" message. If I remove the driver in "domain1/lib/appplib" the same message is recived.

On the other side, if I remove the above files and copy the drivers into de GF server lib directori "gf_dir/lib" all works fine.

What I am doing wrong? I don't want to use the above workaround.

Thanks a lot.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sivakumar Thyagarajan

Hi

>
> I have a GF2 server with some EJB modules that requires JDBC
> resources that uses postgres drivers. Then I have copied the
> postgres drives into the "domain1/lib" dir.

Placing the libraries in domain-dir/lib makes it available in the common classloader and hence visible to all applications deployed in that server instance.

>
> Now I have JAR library package E which works as my "data layer"
> using JPA to persist and query. This package need another postgres
> driver. Also, this package is used by a web application A.
>
> When I deploy the web application A in the server I was copied the
> postgres driver required by the package E in the
> "domain1/lib/applibs".
> The problem is that I get a "no suitable driver found" message. If
> I remove the driver in "domain1/lib/appplib" the same message is
> recived.
> On the other side, if I remove the above files and copy the drivers
> into de GF server lib directori "gf_dir/lib" all works fine.

domain-dir/applibs is available to enable application specific classloading as explained in https://glassfish.dev.java.net/nonav/javaee5/docs/DG/beade.html#gatej

Merely adding a jar to applibs does not make it available to the application. The application
has to be deployed with the --libraries attribute. I think that was missing in your setup. If
you expect the jars to be used by all applications you could place the E package in domain-dir/lib as well.

Please see
http://blogs.sun.com/sivakumart/entry/classloaders_in_glassfish_an_attempt
for more information.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

asantiago
Offline
Joined: 2006-11-09

Thanks for your response.

I am deploying the web application through the web console and in the libraries filed I put "./postgresql-8.2-505.jdbc2ee.jar" .
The JAR is inthe "domain1/lib/applibs" but the error persist:

Caused by: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:postgresql://localhost:5432/subscriptions
Error Code: 0
at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:305)
...
...

Also I tried to deploy it by console:
/asadmin deploy --libraries ./postgresql-8.2-505.jdbc2ee.jar MyWebApp.war

and also using absolute path but the error is the same.

I have put the same driver in the "domain1/lib" dir to use in some JDBC resources used in other apps.

Can be it a problem for classloaders have the same library in both directories ??

Thanks a lot.

mvatkina
Offline
Joined: 2005-04-04

It's the problem with the JDK code. While it allows to register any jdbc driver that can be available on the classpath, it looks for the driver loaded only by the caller's classloader (or classloader abov it) when getConnection() is called on the DriverManager.

So you need to have the jdbc driver loaded either by the same classloader as the TopLink (i.e. place it in the same location as the toplink-essentials.jar) or higher in the classloaders hierarchy. When you have 2 of them, the "wrong one" could've been loaded first, and the 2nd one won't be even checked when the getConnection() call comes in.

Regards,
-marina