-1

I'm deploying a WAR into a Tomcat that has a datasource (Oracle) defined in its context.xml.

My app accesses it by the jndi name. Do I need to embed the jar driver into the war? Or do I just need to has it in Tomcat's classpath?

--edit--

I explained a little bit wrong. I'm providing it in the war and it's working.
But my final doubt I think is if the connection was made by the server itself or the jndi simply gave the data to the application to perform it.
The driver provided in the war is confusing me in this behaviour

Thanks

Ramsés J
  • 357
  • 2
  • 5
  • 1
    What prevents you from testing the two options? ( I would guess that having it in the Tomcat classpath should be sufficient ) – GhostCat Aug 22 '18 at 10:43
  • I explained a little bit wrong. I'm providing it in the war and it's working. But my final doubt I think is if the connection was made by the server itself or the jndi simply gave the data to the application to perform it. The driver provided in the war is confusing me in this behaviour – Ramsés J Aug 22 '18 at 11:03

3 Answers3

1

Application servers don't come bundled with driver jar files for all RDBMS systems. Tomcat certainly doesn't come with Oracle's JDBC driver files. But those classes are still needed to create connections, etc.

So yes, you need to include your driver jar. You might need to install it on the server itself (under <tomcat>/lib)

ernest_k
  • 44,416
  • 5
  • 53
  • 99
1

You shouldn't add the driver to your WAR file in this case, rather deploy it to tomcat's lib directory. Reason: The server opens and maintains the connection, so the server itself needs access to the driver, not only the application.

If you also add the driver to the application, you risk both versions diverting and might end up with duplicate classes on the classpath, which is never fun debugging. Include it once, in the position where it's definitely needed (the server) and remove it from your WAR file.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
0

Placing the JDBC driver in the /lib will make it available for all the apps. However, if you want it specifically for a webapp then you could consider placing the libraries under the /webapps/testapp/WEB-INF/lib. This way, you have control over the version that you want to use.

Nirmala
  • 1,278
  • 1
  • 10
  • 11