如何将H2数据库嵌入到交付给客户端的jar文件中?

发布于 2024-10-07 07:01:17 字数 169 浏览 0 评论 0原文

我在嵌入式模式下使用 H2 数据库作为桌面应用程序。当我将应用程序压缩到 jar 文件中时,数据库文件被省略。因此,当我运行 MyApplication.jar 时,没有任何效果。将 h2.jar 文件嵌入/包含/连接 MyApplication.jar 的正确方法是什么?或者也许还有另一种方式来捆绑提供数据库和应用程序?

I use H2 database for a desktop application in embedded mode. When I compress the application into jar file the database file is omitted. So, when I run MyApplication.jar nothing works. What is the correct way to embed/include/connect h2.jar file with MyApplication.jar? Or maybe there is another way to deliver database and application in the bundle?

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

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

发布评论

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

评论(4

旧伤还要旧人安 2024-10-14 07:01:17

一种常见的方案是将 h2.jar 放在与您的应用程序相关的 lib 目录中,并在 JAR 清单中包含一个 Class-Path 条目:其条目:

Class-Path: lib/h2.jar lib/…

附录:这个小型项目包含一个指向JAR 规范 和用于检查清单的便捷实用程序就地

One common scheme is to put h2.jar in a lib directory relative to your application and include a Class-Path entry in your JAR's manifest with an entry for it:

Class-Path: lib/h2.jar lib/…

Addendum: This small project includes a link to the JAR specification and a handy utility for examining the manifest in situ.

极度宠爱 2024-10-14 07:01:17

如果您使用 Maven 构建项目,只需使用 maven-shade-plugin...效果很好,控制也很好,我已经经常使用它了。

为了嵌入所有依赖项,您可以编写如下内容:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.4</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

然后,只需使用普通的“mvn package”,您就可以将所有依赖项的 jar 包含在应用程序 jar 中。

通过进一步配置,您可以控制包含哪些内容和不包含哪些内容。

If you are using Maven to build your project, just use maven-shade-plugin... great results and control, I've been using it a lot.

For embedding all your dependencies you would write something like:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.4</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

Then with just a normal "mvn package" you'll have all your dependencies' jars included in your application jar.

With further configuration you can control what gets included and what not.

困倦 2024-10-14 07:01:17

如果您想将数据库本身放入 jar 文件中,那么以下解释可能会有所帮助:
http://www.h2database.com/html/features.html#database_in_zip

H2 论坛中的此帖子

If you want to put the database itself in your jar file, then this explanation might help:
http://www.h2database.com/html/features.html#database_in_zip

This is also discussed in this thread in the H2 forum.

尐偏执 2024-10-14 07:01:17

如果您使用 Maven 构建项目,请查看 maven- assembly-plugin (jar-with-dependencies)。这将生成一个包含所有依赖项的 jar。

If you're using maven to build you project take a look maven-assembly-plugin (jar-with-dependencies). This would produce single jar with all dependencies packed into it.

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