DEV Community

Cover image for Driver class not found: com.sap.cloud.db.jdbc.Driver
Rohith V
Rohith V

Posted on

Driver class not found: com.sap.cloud.db.jdbc.Driver

Me and my friend decided to start a project with the applications of Microservices, Spring Data JPA, Spring framework.
As a part of that, we implemented our databases on SAP HANA. In order to use it in our Java applications, as we all know, we need to include the dependency in our POM.xml.
The dependency I included is

<dependency>
    <groupId>com.sap.cloud.db.jdbc</groupId>
    <artifactId>ngdbc</artifactId>
    <version>2.7.15</version>
    <type>pom</type>
    <scope>test</scope>
</dependency>
Enter fullscreen mode Exit fullscreen mode

The sets up the application.properties and ran our application. But oopss..... We were getting Driver class not found error.
What!!!! I once again checked the pom.xml file and yes the driver class dependency is added. Once again the program was run and the same error pops out.
The next step is quite similar for every developer. I started checking this on stack overflow and other resources. I even implemented a CloudConfig class which is actually of no use.. WOW!!!
There were many answers that was shown up, but nothing matches our error.
We stopped that day and continued on this the next day. Once again examined the pom.xml and yes, there is something special in the pom.xml. If everyone noticed, its great because it took almost 2 days for me to not that.

I was giving the <scope>test</scope>.

This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.

So that was the problem and the class was not being used for the normal purpose. So I just removed it and yeah!!! The application started successfully and we took one more step ahead in our project.

The Updated pom.xml

<dependency>

<groupId>com.sap.cloud.db.jdbc</groupId>
<artifactId>ngdbc</artifactId>
<version>2.7.14</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Looking forward with more challenges in this project....

Top comments (1)

Collapse
 
0xamitshukla profile image
Amit Kumar

That's correct. It is required to remove the tag
<type>pom</type>
. It fails to load with this tag, even if <scope> tag is already removed.

For scope, either you can remove it, or make it runtime. Below is valid entry and loads on doing the mvn install

<!-- https://mvnrepository.com/artifact/com.sap.cloud.db.jdbc/ngdbc -->
<dependency>
    <groupId>com.sap.cloud.db.jdbc</groupId>
    <artifactId>ngdbc</artifactId>
    <version>2.19.16</version>
    <scope>runtime</scope>
</dependency>
Enter fullscreen mode Exit fullscreen mode