This tutorial shows you how to add Oracle JDBC driver into Maven local repository and also how to reference it in pom.xml. Due to Oracle license restrictions, the Oracle JDBC driver is not available in the public Maven repository. To use the Oracle JDBC driver with Maven, we have to download and install it manually into Maven local repository
Let’s begin:
Get Oracle JDBC Driver
Depends your need, you can download Oracle JDBC Driver that you want to use for your oracle version. For example, Oracle Database 12.2.0.1 works with Oracle JDBC Driver named ojdbc8.jar. Oracle Database 12.1.0.2 works with ojdbc7.jar.
Visit Oracle website to get the Oracle JDBC driver – ojdbc8.jar or ojdbc7.jar
Maven install
To install the Oracle jdbc drivers, go to the console:
Run the below command to install ojdbc8.jar
1 2 |
mvn install:install-file -Dfile={Path/to/your/ojdbc8.jar} -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar |
Run the below command to install ojdbc7.jar
1 2 |
mvn install:install-file -Dfile={Path/to/your/ojdbc7.jar} -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0 -Dpackaging=jar |
See the result when we try to install ojdbc7.jar in maven local repository. Run the maven command line, the output will show like below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
mvn install:install-file -Dfile=D:\\download\\ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0 -Dpackaging=jar [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom --- [INFO] Installing D:\download\ojdbc7.jar to C:\Users\javabycode\.m2\repository\com\oracle\ojdbc7\12.1.0\ojdbc7-12.1.0.jar [INFO] Installing C:\Users\javabycode\AppData\Local\Temp\mvninstall2095378400735903278.pom to C:\Users\javabycode\.m2\repository\com\oracle\ojdbc7\12.1.0\ojdbc7-12.1.0.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.332 s [INFO] Finished at: 2017-04-13T21:26:03+08:00 [INFO] Final Memory: 8M/309M [INFO] ------------------------------------------------------------------------ |
You can do the same with ojdbc8.jar
Configure Oracle JDBC driver dependency
If you want to use ojdbc8.jar dependency, add this to the pom.xml
1 2 3 4 5 6 7 8 |
<dependencies> <!-- ojdbc8.jar example --> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>12.2.0.1</version> </dependency> </dependencies> |
If you want to use ojdbc7.jar dependency, add this to the pom.xml
1 2 3 4 5 6 7 8 |
<dependencies> <!-- ojdbc7.jar example --> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc7</artifactId> <version>12.1.0</version> </dependency> </dependencies> |
Ok done, now you can use Oracle JDBC driver dependency same as other dependencies.
That’s all on the tutorial How to add Oracle JDBC driver into Maven local repository
References
Oracle Database JDBC Driver