1

I'm trying to add external jar file in my spring boot project.

In pom.xml I have:

<dependencies>
    <dependency>
        <groupId>ojdbc14</groupId>
        <artifactId>ojdbc14</artifactId>
        <scope>system</scope>
        <version>1.0</version>
        <systemPath>C:\Users\myUser\Dropbox\Projects\myProject\ojdbc14.jar</systemPath>
    </dependency>
</dependencies>

In a class in a java file I have:

Class.forName("oracle.jdbc.driver.OracleDriver");

When I run the project I get the following error:

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at com.ucy.MyApi.getdbConnection(myApi.java:23)
zinon
  • 4,427
  • 14
  • 70
  • 112
  • 2
    Are you really still using Java 1.4? –  Apr 27 '21 at 13:36
  • @a_horse_with_no_name No, but a system that we are connecting unfortunately yes and I have to connect with it. – zinon Apr 27 '21 at 13:40
  • JDBC drivers are generally backwards compatible, so you can use a newer driver to connect to an older database. – Andreas Apr 27 '21 at 13:43
  • 1
    The `system` scope is similar to `provided`, meaning that the jar will be provided by something (usually the container) during runtime, but will be available for compile-time from a system path. So you're using the wrong scope. – Kayaman Apr 27 '21 at 13:46

2 Answers2

1

This might help ojdbc14.jar vs. ojdbc6.jar

Are you sure that's the correct definition in the POM?

I use this:

<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>18.3.0.0</version>
</dependency>

Check for the specific version of Oracle and the proper jar version. It should not need the system path.

sproketboy
  • 8,967
  • 18
  • 65
  • 95
1

You need to use a maven command to install a 3rd party jars:

mvn install:install-file -Dfile=C:\Users\myUser\Dropbox\Projects\myProject\ojdbc14.jar -DgroupId=ojdbc14 -DartifactId=ojdbc14 -Dversion=1.0 -Dpackaging=jar

https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

after that change your pom file like following:

<dependency>
        <groupId>ojdbc14</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
</dependency>
J Asgarov
  • 2,526
  • 1
  • 8
  • 18