Java Mailing List Archive

Home » Home (12/2007) » Tomcat Users »

Tomcat and webapplication-specific java.library.path

Erik Winlöf


I have a problem with Tomcat and the java-library.path.
(My problem isn't Oracle-specific but it is when I use Oracle that problem
appears since Oracle uses the java.library.path)

What I have managed to do:
Oracle JDBC with works fine if I:
- put ojdbc14.jar in ${CATALINA_HOME}/common/lib
- set ORACLE_HOME to the correct directory
- set LD_LIBRARY_PATH (java.library.path) to include the directory with
 the needed .so-file

However this is not exactly what I wan't to do. Instead of setting the
variables in the shell I want to set them from a Java-class when it is
invoked by Tomcat.

So I set ORACLE_HOME to the same directory as above and include the directory
with the .so-file in the LD_LIBRARY_PATH by doing this:

System.out.println("JLP =" + System.getProperty("java.library.path");
System.out.println("OH  =" + System.getProperty("ORACLE_HOME");

System.setProperty("ORACLE_HOME", dbHomePath);
String jlp = java.lang.System.getProperty("java.library.path");
System.setProperty("java.library.path", dbLibraryPath + ":" + jlp);

System.out.println("JLP2 =" + System.getProperty("java.library.path");
System.out.println("OH2 =" + System.getProperty("ORACLE_HOME");

String dsJNDIName = "java:/comp/env/jdbc/orgdbDataSource";
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup(dsJNDIName);

When I print these variables they look exactly as I want them to look,
just like they did when everything worked (the top of the mail
"What I have managed to do"). They look like this:

JLP =null
OH  =/appl/oracle/product/9.2.0/

JLP2 =/opt/sun-jdk-1.4.2/jre/lib/i386/client:/opt/sun-jdk-1.4.2/jre/lib/i386:/opt/sun-jdk-1.4.2/jre/../lib/i386:/appl/mqm/java/lib/:/opt/mqm/java/lib
OH2 =/appl/oracle/product/9.2.0/lib/:/opt/sun-jdk-1.4.2/jre/lib/i386/client:/opt/sun-jdk-1.4.2/jre/lib/i386:/opt/sun-jdk-1.4.2/jre/../lib/i386:/appl/mqm/java/lib/:/opt/mqm/java/lib

(Notice the change with /opt/sun-jdk-1.4.2/jre/lib/i386/client in the
start of the path)

My thinking is this (based on what I have read about the ClassLoader):

Since the ojdbc14.jar is placed in /common/lib, the jar doesn't
include my webapplication-spcific java.library.path since it is supposed
to be shared by all webapplications. However, if this is the case, it is
kind of strange since it is my webapplication that uses and loads ojdbc14
and NOT ojdbc14 that uses my webapplication. Therefore I think that ojdbc14 should
use my java.library.path.

This is the error I get by the way:

java.lang.UnsatisfiedLinkError: no ocijdbc9 in java.library.path
 java.lang.ClassLoader.loadLibrary (
 java.lang.Runtime.loadLibrary0 (
 java.lang.System.loadLibrary (
    org.apache.commons.dbcp.DriverConnectionFactory.createConnection (  
 org.apache.commons.dbcp.PoolableConnectionFactory.makeObject (  
 org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory (  
 org.apache.commons.dbcp.BasicDataSource.createDataSource (  
 org.apache.commons.dbcp.BasicDataSource.getConnection (
 org.apache.catalina.valves.ErrorReportValve.invoke (
 org.apache.coyote.tomcat5.CoyoteAdapter.service (
 org.apache.coyote.http11.Http11Processor.process (
 org.apache.tomcat.util.threads.ThreadPool$ (

To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)

©2008 - Jax Systems, LLC, U.S.A.