GullerYA
GullerYA

Reputation: 1776

Apache Derby 10.15.* - java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver

While trying to use Apache Derby DB (aka JavaDB, being once part of JDK) as an embedded in-memory DB for tests, I've encountered ClassNotFoundException thrown by HikariCP not being able to instantiate org.apache.derby.jdbc.EmbeddedDriver.

The project set up via Maven. Derby dependency is:

<dependency>
    <artifactId>derby</artifactId>
    <groupId>org.apache.derby</groupId>
    <version>10.15.2.0</version>
    <scope>test</scope>
</dependency>

HikariCP configuration is:

HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
config.setJdbcUrl("jdbc:derby:memory:TestsDB;create=true");
return new HikariDataSource(config);

There are few threads that mention ClientDriver but I do need the EmbeddedDriver for in-memory JDBC access.

Any ideas?

Upvotes: 2

Views: 1428

Answers (1)

GullerYA
GullerYA

Reputation: 1776

Apparently things changed from Derby version 10.14.* towards version 10.15.*.

The latter (which I'm using) indeed has no such a class in its JAR.

After some search in the sources I've found that org.apache.derby.jdbc.EmbeddedDriver has been moved to the tools JAR, so make sure to add the following dependency to your pom.xml too:

<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derbytools</artifactId>
    <version>10.15.2.0</version>
    <scope>test</scope>
</dependency>

Note: of course, adjust the version of this artifact to be the same as the main one, whatever it is in your case.

To Apache Derby guys: if this change is intent-full, I suggest to change the main Derby artifact description, which still misleadingly states "Contains the core Apache Derby database engine, which also includes the embedded JDBC driver" (emphasis is mine [YG]).

Upvotes: 4

Related Questions