Spring boot Cannot load driver class: oracle.jdbc.OracleDrive

31.8k Views Asked by At

I have driver class in class-path in my jar:

2015-06-18 12:21:40.290 INFO 9453 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: ..... jar:file:/{projecthome}/rest-test/target/rest-test-0.1.0.jar!/lib/ojdbc6-11.2.0.3.0.jar!/]

I got exception:

Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.OracleDrive

My pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>rest-test</artifactId>
    <version>0.1.0</version>
    <packaging>jar</packaging>

    <properties>        
        <start-class>hello.Application</start-class>
        <java.version>1.8</java.version>
    </properties>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.4.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-dbcp</artifactId>
            <version>${tomcat.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>                
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3.0</version>
            <scope>compile</scope>
        </dependency>                
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
    <name>rest-test</name>
</project>
4

There are 4 best solutions below

2
On
  1. In pom.xml add dependency as told by Santosh.

  2. In Eclipse IDE Right click upon your Project and select -- Run As -- Maven build... -- in Goals provide below line and Run. I have just removed mvn and pointed ojdbc6.jar location in my local machine.

install:install-file -Dfile=D:\oracle11gXE\app\oracle\product\11.2.0\server\jdbc\lib\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

  1. Again in Eclipse IDE Right click upon your Project and select -- Maven -- Update Project... -- select Force Update of Snapshots/Releases along with other default options and click OK.

  2. ojdbc6-11.2.0.jar should reflect under Maven Dependencies.

0
On

step 1:You POM.xml file should be

<dependency>
     <groupId>com.oracle</groupId>
     <artifactId>ojdbc6</artifactId>
     <version>11.2.0</version>
</dependency>

Step 2:Download the ojdbc6 driver from oracle website and keep it in your local machine.

step 3:Run maven below command.Dfile is the location where i kept my jar file downloaded from oracle website

mvn install:install-file -Dfile=C:\Users\santosh\.m2\repository\com\oracle\ojdbc6\11.2.0\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

After running maven command it should create ojdbc6-11.2.0 in your maven repository.After that your problem should be fixed.

0
On

Download ojdbc6.jar from Oracle website or if you install oracle11g in your local system you can find ojdbc in jdbc/lib folder.

Add that ojdbc.jar right click --> build path--> configure build path--> Add external jars--> your local machine ojdbc path -->ok.

It worked in my case.

0
On

Make sure that in your IDE you click maven reimport if it is not reimporting automatically (i.e. IntelliJ: right click project, Maven, Reimport), as it will compile fine without being on the classpath, but fail at runtime