带有 Maven 插件的轻量级 Java 数据库用于启动/停止?

发布于 2024-08-11 16:26:27 字数 158 浏览 1 评论 0原文

对于单元测试、演示和 Hibernate 任务,我想使用小型且简单的 Java 数据库,如 Derby / Java DB 或 HSQLDB,可以从 Maven 中调用。

到目前为止,我还没有找到一个可以下载和启动 Java DB(这是我目前最喜欢的)或类似的东西的 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 Java DB (which is my favorite at the moment) or something similar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柳絮泡泡 2024-08-18 16:26:27

单元测试的一个简单设置是在内存中启动 hsqldb:

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

无需启动和停止。 JDBC 驱动程序将“启动”数据库。

您也可以将其用于演示。如果您在应用程序启动时初始化数据库。

数据库设置可以通过 hibernate.hbm2ddl.auto


Edit by kdgregory:

要让 Maven 仅在测试阶段的依赖项中包含 HSQLDB,请在 POM 中使用:

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

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>
请帮我爱他 2024-08-18 16:26:27

我的回答中所述,您可以通过我编写的 derby-maven-plugin 使用 Derby 作为数据库,该插件可以在 上找到GitHub 和通过 Maven Central。使用 Derby 作为用于测试的内存数据库,就 CI 而言,您的生活将变得简单 —— 无需仅为您的测试安装和设置外部软件,而您只需使用 Maven 即可完成这一切。

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.

独木成林 2024-08-18 16:26:27

我不知道它是否支持你所需要的,但 SQLite 非常受欢迎,它似乎有任何东西的集成插件。一探究竟。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文