Install ojdbc driver to Maven local repository


Install ojdbc driver to Maven local repository

Hi, I am Malathi Boggavarapu working at Volvo Group and i live in Gothenburg, Sweden. I have been working on Java since several years and had vast experience and knowledge across various technologies.

In recent days i have a been building the sample REST api using Spring Boot framework and Gradle. So in no time i jumped to the website Spring Initializer (https://start.spring.io/) immediatly and generated the project with required dependencies such as Web, Actuator, JPA and JDBC.

I added the jdbc dataSoruce configuration properties to application.yml inorder to connect to Oracle database. See below

spring:  
    datasource:    
      url: jdbc:oracle:thin:@[host_name]:[port]/[service_name]
      username: [user_name]
      password: [password]
      driver-class-name: oracle.jdbc.driver.OracleDriver

But once i start the Spring boot application it started complaining 'Can not load OracleDriver' and couldn't start the application. I googled and found that ojdbc jar files were not available in Maven central repository and we need to download the ojdbc jar file to local system and install it in Maven local repository. Finally we need to update build.gradle accordingly to add jdbc support in the application.

The reason why jdbc driver is not available in Maven central repository is due the security concerns that oracle corporation has imposed. So we can not find jdbc driver in Maven public repository and also there is no surprise that many of  libraries were not available in Maven central or public repository.


Now let's see how to install ojdbc jar file into your Maven local repository

Download ojdbc.jar

Go to Oracle website and download ojdbc jar file of your choice. It could be ojdbc6.jar or ojdbc8.jar. I prefer ojdbc8.jar.

Maven Install

mvn install:install-file -Dfile='{Path/to/your/ojdbc8.jar}' -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar

Example:


Check the installed ojdbc in Mavel local repository

Now go to .m2/repository/com/ folder in your system and there you will find oracle installed in your local maven repo.


Update your build file(build.gradle or pom.xml)

Do not forget to add mavelLocal() to gradle build file as the jdbc driver is installed locally. Same is applicable to Maven pom.xml as well.

Gradle


buildscript {
   ext {
      springBootVersion = '2.1.1.RELEASE'   }
   repositories {      
      maven {
         url "https://plugins.gradle.org/m2/"      }
      mavenCentral()
      mavenLocal()
   }
   dependencies {
      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
   }
}

dependencies {
    implementation 'com.oracle:ojdbc8:12.2.0.1'}

Maven

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


Now you are done. Hope it is helpful




Comments

Popular posts from this blog

Bash - Execute Pl/Sql script from Shell script

Gradle Fundamentals

Load Balancing using Spring Cloud Netflix Ribbon