1

I have a Maven project that is distributed commercially that offers the ability to connect to many different databases via JDBC. Normally the customers place the necessary JDBC drivers in their web server's lib directory to make them accessible. We can't include certain jdbc drivers in the pom, for example Oracle, due to it's license type.

I'm trying to use an Oracle JDBC connection in the app while running in Eclipse. I need to get the JDBC jar on the class path and for some reason can't seem to be able to do that without adding it to the pom.xml via maven dependency.

I thought for sure going to Properties-->Java Build Path --> Libraries --> Add External JARs would work. When added to the build path in that way it shows correctly in the package explorer but if I run Class.forName at run time it throws ClassNotFoundException. Why isn't it on the class path at that point?

nmb1106
  • 385
  • 1
  • 5
  • 20

2 Answers2

2

Take a look at the following descriptive article, which gives the shortcuts to setting a classpath to your throw-away code or to have a modest solution to manage your classpath dependencies and then to a complete and a professional solution to manage and even automate your classpath dependencies - should there be a need to have these automated for a larger projects.

It is a better way to set your CLASSPATH variable if you are not going to change any of those jar versions very frequently or else you might end up hours of your valuable time debugging the wrong side of the problem.

Hope this helps you understand and also resolve your problem!

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
  • Makes sense, I got it working by adding it to the classpath of the run / debug configurations of the server rather then the project. But I like this approach as well. Thank you – nmb1106 Apr 21 '17 at 15:48
0

I would include the relevant jars into the pom, but make them <optional>. Then, they are not packaged into the application but they can be provided by the user.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142