Here’s a simple guide to show you how to add an Oracle JDBC driver into your Maven local repository, and also how to reference it in pom.xml

Tested with Oracle database 19c and Java 8

Note

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, you have to download and install it into your Maven local repository manually.

1. Get Oracle JDBC Driver

Note
Read this What are the Oracle JDBC releases Vs JDK versions?

Visit Oracle database website and download it.

In this example, we selected Oracle database 19c and ojdbc8.jar for Java 8 project.

Note
Alternatively, you can get the Oracle JDBC driver from the Oracle database installed folder, for example: {ORACLE_HOME}\jdbc\lib\ojdbc8.jar

2. Maven Install ojdbc8.jar

2.1 Upload or install the downloaded ojdbc.jar into the Maven local repository.

ojdbc8.jar

$ mvn install:install-file -Dfile=path/to/your/ojdbc8.jar -DgroupId=com.oracle 
	-DartifactId=ojdbc8 -Dversion=19.3 -Dpackaging=jar

For older version.

ojdbc7.jar

$ mvn install:install-file -Dfile=path/to/your/ojdbc7.jar -DgroupId=com.oracle 
	-DartifactId=ojdbc7 -Dversion=12.2.0.1 -Dpackaging=jar

ojdbc6.jar

$ mvn install:install-file -Dfile=path/to/your/ojdbc6.jar -DgroupId=com.oracle 
	-DartifactId=ojdbc6 -Dversion=11.2.0.4 -Dpackaging=jar

Note

The -Dversion= is depends on your database version, in this example, we are using Oracle database 19c, so put -Dversion=19.3

2.2 Full example to install a ojdbc8.jar

Terminal

C:\> mvn install:install-file -Dfile=d:/projects/ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=19.3 -Dpackaging=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing d:\projects\ojdbc8.jar to C:\Users\favtuts\.m2\repository\com\oracle\ojdbc8\19.3\ojdbc8-19.3.jar
[INFO] Installing C:\Users\favtuts\AppData\Local\Temp\mvninstall14285592711568231406.pom 
		to C:\Users\favtuts\.m2\repository\com\oracle\ojdbc8\19.3\ojdbc8-19.3.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.872 s
[INFO] Finished at: 2019-06-20T12:36:18+08:00
[INFO] ------------------------------------------------------------------------

3. pom.xml

Now, we can define the Oracle JDBC driver dependency like this:

pom.xml

	<dependency>
		<groupId>com.oracle</groupId>
		<artifactId>ojdbc8</artifactId>
		<version>19.3</version>
	</dependency>

For older version:

pom.xml

	<!-- ojdbc7.jar -->
	<dependency>
		<groupId>com.oracle</groupId>
		<artifactId>ojdbc7</artifactId>
		<version>12.2.0.1</version>
	</dependency>
	
	<!-- ojdbc6.jar -->
	<dependency>
		<groupId>com.oracle</groupId>
		<artifactId>ojdbc6</artifactId>
		<version>11.2.0.4</version>
	</dependency>

4. System Path

Alternatively, we can just download the .jar and tell the project to find the .jar in the system path like this:

pom.xml

	<dependency>
		<groupId>com.oracle</groupId>
		<artifactId>ojdbc</artifactId>
		<version>8</version>
		<scope>system</scope>
		<systemPath>d:/projects/ojdbc8.jar</systemPath>
	</dependency>

pom.xml

	<dependency>
		<groupId>com.oracle</groupId>
		<artifactId>ojdbc</artifactId>
		<version>8</version>
		<scope>system</scope>
		<systemPath>${project.basedir}/lib/ojdbc8.jar</systemPath>
	</dependency>

Download Source Code

$ git clone https://github.com/favtuts/java-core-tutorials-examples.git

$ cd java-jdbc/oracle

References

Leave a Reply

Your email address will not be published. Required fields are marked *