开发者

Lightweight Java database with Maven plugin for starting/stopping?

开发者 https://www.devze.com 2022-12-11 12:04 出处:网络
For unit tests, demonstrations and Hibernate tasks I would like to use a small and simple Java database like Derby / Java DB or HSQLDB, which can be called from within Maven.

For unit tests, demonstrations and Hibernate tasks I would like to use a small and simple Java database like Derby / Java DB or HSQLDB, which can be called from within Maven.

So far I have not found a Maven plugin which can download and launch Jav开发者_开发技巧a DB (which is my favorite at the moment) or something similar.


An simple setup for unit tests is to start hsqldb in memory:

db.connection.driver_class=org.hsqldb.jdbcDriver
db.connection.url=jdbc:hsqldb:mem:aname
db.connection.username=sa
db.connection.password=
hibernate.dialect=org.hibernate.dialect.HSQLDialect

No start and stop needed. The JDBC driver will "start" the database.

You could use that for demonstrations, too. If you're initializing the database while the applications starts.

The database setup can be done with hibernate.hbm2ddl.auto.


Edit by kdgregory:

To have Maven include HSQLDB in the dependencies for the test phase only, use this in your POM:

<dependency>
    <groupId>hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <version>1.8.0.7</version>
    <scope>test</scope>
</dependency>


As described in my answer here, you can use Derby as your database via the derby-maven-plugin which I wrote and is available on GitHub and via Maven Central. With Derby as your in-memory database for tests, your life would be simple, in terms of CI -- no need to install and setup an external bit of software just for your tests, when you can just do it all with Maven.


I've no idea whether it supports what you need, but SQLite is so immensely popular that it seems to have integration plugins with about anything. Check it out.

0

精彩评论

暂无评论...
验证码 换一张
取 消