简体   繁体   中英

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?

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]).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM