How to add Oracle JDBC driver in your Maven local repository

Here’s a 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.

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 manually into your Maven local repository.

1. Get Oracle JDBC Driver

Two ways to get the Oracle jdbc driver :

1. Visit Oracle website to get the Oracle JDBC driver – ojdbc6.jar or ojdbc7.jar

2. Not recommend, but you can get the JDBC driver from the Oracle database installed folder, for example – {ORACLE_HOME}\jdbc\lib\ojdbc6.jar

2. Maven Install

To install the Oracle jdbc drivers :

2.1 ojdbc6.jar


$ mvn install:install-file -Dfile={Path/to/your/ojdbc6.jar} 
      -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

2.2 ojdbc7.jar


$ mvn install:install-file -Dfile={Path/to/your/ojdbc7.jar} 
      -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0 -Dpackaging=jar

Full example to install a ojdbc7.jar

Terminal

> mvn install:install-file -Dfile=C:\\OracleJDBC\\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 C:\OracleJDBC\ojdbc7.jar to C:\Users\mkyong\.m2\repository\com\oracle\ojdbc7\12.1.0\ojdbc7-12.1.0.jar
[INFO] Installing C:\Users\mkyong\AppData\Local\Temp\mvninstall2095378400735903278.pom 
       to C:\Users\mkyong\.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-02-13T21:26:03+08:00
[INFO] Final Memory: 8M/309M
[INFO] ------------------------------------------------------------------------

Done.

3. pom.xml

pom.xml

<dependencies>

        <!-- ojdbc6.jar example -->
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0</version>
        </dependency>

        <!-- ojdbc7.jar example -->
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc7</artifactId>
            <version>12.1.0</version>
        </dependency>

</dependencies>

References

  1. How to include library manually into Maven local repository

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
KingFeming
Guest
KingFeming

If you want ojdbc, What you can do is download the ojdbc6.jar and include it as a “Web App Libraries” by Right Clicking your project and select java build path and under Libraries select Add external jars and select the location to the jar that you have downloaded (ojdbc6.jar).

Please not this instruction is given for Eclipse.

neha
Guest
neha

com.oracle
ojdbc6
11.2.0

missing arifects in pom.xml

Yuli
Guest
Yuli

I have the similar issue say this “artifactId missing”

Guest
Guest
Guest

I believe it is because oracle does not allow their driver to be on maven repo site anymore. Need to be added manually. (Or so I believe)

Daniel
Guest
Daniel

Thank you so much! All your post are amazing!

Dozer
Guest
Dozer

Thank you for sharing!

AP
Guest
AP

thanks lot

Johnny O
Guest
Johnny O

I want to recommend you’re an exellent resource, thanks mkyong !!

Pablo Gilvan
Guest
Pablo Gilvan

Thank you, you saved me.

Fatos
Guest
Fatos

Thank you very much

guache
Guest
guache

Thanks so much dude! All your work are so great! Keep it up! :D

March per l'Unione Europea
Guest
March per l'Unione Europea

Great!!

Waseem
Guest
Waseem

Thanks, very helpful

Guest
Guest
Guest

am getting this error ..please help me out :-
mvn install:install-file -Dfile=D:oraclexeapporacleproduct11.2.0serverjdbclib -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

trackback
Deb's Desk – Maven 3 + Hibernate 3.6 + Oracle 11g Example (XML Mapping)

[…] For Oracle JDBC Driver Read this guide – How to add Oracle JDBC driver in your Maven local repository […]

Oik
Guest
Oik

I’m newbie in this framework. can you tell me where i should execute mvn install command in windows?

Ankur Saxena
Guest
Ankur Saxena

try out in cmd..dos prompt

RM
Guest
RM

Genius. Thanks!

Vijay Kumar
Guest
Vijay Kumar

Thanks. It was wonderful!

Carlos Gonzaga
Guest
Carlos Gonzaga

Very good stuff.
Thank you mkyong

trackback
Oracle 11 XE & JDBC | Li Guoliang

[…] [http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/] […]

paiker
Guest
paiker

I am getting the below exception, could you please suggest.

[ERROR] Failed to execute goal on project SpringExamplesDAO: Could not resolve dependencies for project com.mkyong.common:SpringExamplesDAO:jar:1.0-SNAPSHOT: Could not find artifact com.oracle:ojdbc6:jar:11.2.0 in central (http://repo.maven.apache.org/maven2) -> [Help 1]

Though i already installed ojdbc6.jar in local .m2

paiker
Guest
paiker

Can anyone please help me as , my maven is not picking up the com.oracle:ojdbc6:jar:11.2.0 jar from local repository within .m2/

It is pointing to maven repository from internet and it doesn’t find jar there, though i have registered it there in .m2/ with the help of above procedure

paiker
Guest
paiker

Guys,

Problem has been solved now, there was some version problem,
I had jdk1.6 with maven-3.0.4.

Now i have installed Maven 2.2.1, and problem has been solved.

Thanks

trackback
install driver oracle ojdbc14-9i ke dalam maven repo | saifiahmada
trackback
Spring – Oracle Connection Pool Configuration | Peace be with you
mano
Guest
mano

Hi mkyong…
the jdbc driver jar is not getting installed in m2 repository when i am executing the command ..
mvn install:install-file -Dfile=C:\app\msarilla\product\11.2.0\dbhome_2\jdbc\lib\ojdbc6.jar -DgroupId=com.oracle – DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar -DgeneratePom=true
when i execute the command the build was successful but the ojdbc6 file is not installed to the m2 repo.
i am getting the following message in the build console:

[INFO] Installing C:\apache-maven-3.0.4\bin\ojdbc6.jar to C:\Users\msarilla\.m2\
repository\com\oracle\ojdbc6\11.2.0\ojdbc6-11.2.0.jar
[DEBUG] Skipped re-installing C:\apache-maven-3.0.4\bin\ojdbc6.jar to C:\Users\m
sarilla\.m2\repository\com\oracle\ojdbc6\11.2.0\ojdbc6-11.2.0.jar, seems unchang
ed..
from the above messages i can see that the jar installation is skipped coz its already there..but actually there is no ojdbc6 jar…
any suggestions…

anamika mishra
Guest
anamika mishra

why not simply add the following repository to your project

<repositories>
    <repository>
      <id>codelds</id>
      <url>https://code.lds.org/nexus/content/groups/main-repo</url>
    </repository>
  </repositories>
Dauka
Guest
Dauka

Thank you! You helped me out ^_^

Balamurugan
Guest
Balamurugan

Hi,
I have the same problem what sajid is facing. Anyting specific, do I need to do?

sajid
Guest
sajid

Hi, i completed the steps above, but still facing ‘Missing artifact com.oracle:ojdbc6:jar:11.2.0.3:compile’.
Also, after step 2, i think the jar file should be automatically placed in repository, but it doesnt happen and i can see only _maven.repositories, ojdbc6-11.2.0.3.pom and ojdbc6-11.2.0.3.jar.lastUpdated. Is there anything that i am missing.

Thanks.
sajid

Ben Weaver
Guest
Ben Weaver

This and other pages you have put are excellent. Very practical and clear–real time-savers. Thank you.

JAY
Guest
JAY

This article is nice and simple to understand.

elres
Guest
elres

???????????? ?????????? ???????? ?????????????? ? ??????

trackback
Maven 3 + Hibernate 3.6 + Oracle 11g Example (XML Mapping)

[…] For Oracle JDBC driver, you need to install it into your local maven repository manually. For Oracle JDBC Driver Read this guide – How to add Oracle JDBC driver in your Maven local repository […]