Dreamer
Dreamer

Reputation: 7551

Tomcat - Oracle JNDI connection - how application can run without ojdbc jar in $CATALINA_HOME/lib

I am setting up a legacy Web application and having a few questions. Currently the web application packed ojdbc jar under WEB-INF/lib and Tomcat context.xml has a resource tag referring to JNDI datasoure. It's Oracle database so the connection string is through oci (I am using Windows system)

<Resource name="jdbc/MainSource" 
      auth="Container" type="javax.sql.DataSource" 
      driverClassName="oracle.jdbc.driver.OracleDriver" 
      url="jdbc:oracle:oci:@username/password@tnsinstance" 
      validationQuery="SELECT sysdate from DUAL;"
      jdbcInterceptors="ConectionState" />

From what I can see, the Tomcat server don't have any ojdbc.jar under $CATALINA_HOME/lib directory. Then here are my questions

  1. How could the application run on JNDI if ojdbc is only available under WEB-INF/lib?
  2. Does OCI exempt the JNDI from providing the ojdbc jar (my understanding, it should not because Tomcat still look for implementation of driverClassName)?

Updated: A little further details to question2 - there is Oracle client installed on the server and within the installation there is ojdbc jar file, which should be in $PATH after ORACLE_HOME being registered. However I still don't think Tomcat server will reach out to OS $PATH to get ojdbc jar even if it is an Oracle OCI connection, according to Tomcat JNDI doc

Upvotes: -1

Views: 52

Answers (2)

Jan Suchanek
Jan Suchanek

Reputation: 301

Fallback to application-scoped resources occurs when an application avoids using the container-managed JNDI datasource and instead relies on resources bundled and loaded within the application itself. This can happen due to explicit configuration or as a backup mechanism when JNDI resources fail to initialise.

If the ojdbc.jar is missing from $CATALINA_HOME/lib, Tomcat cannot initialise the JNDI datasource, however, the application can still function if it directly loads the driver from WEB-INF/lib. Many legacy web applications were not designed to use container-managed JNDI datasources by default. They often have hardcoded connection logic as a fallback.

Upvotes: 0

Saurabh Verma
Saurabh Verma

Reputation: 300

  1. You should put ojdbc jar in $CATALINA_HOME/lib.
  2. No

Upvotes: -1

Related Questions