How to add Oracle JDBC driver in your Maven local repository

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.

Oracle JDBC driver

Oracle JDBC driver

In this example, we selected Oracle database 12c 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

Copy

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

Copy

ojdbc6.jar

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

Copy

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\mkyong\.m2\repository\com\oracle\ojdbc8\19.3\ojdbc8-19.3.jar
[INFO] Installing C:\Users\mkyong\AppData\Local\Temp\mvninstall14285592711568231406.pom
		to C:\Users\mkyong\.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] ------------------------------------------------------------------------

Copy

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>

Copy

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>

Copy

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>

Copy

pom.xml

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

Copy

Download Source Code

$ git clone https://github.com/mkyong/java-jdbc.git

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值