用sqlite驱动程序jar可执行文件 [英] Jar executable with sqlite driver

查看:90
本文介绍了用sqlite驱动程序jar可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个连接到 sqlite 驱动程序的代码,该驱动程序位于 CLASSPATH 中,并读取了一些数据库文件。我想创建一个可执行文件,可以在没有 sqlite 驱动程序的计算机上使用。

I made a code that connects to my sqlite driver which is in the CLASSPATH and reads some database file. I want to create an executable which can be used on computers that don't have the sqlite driver.

如果我这样做:

jar cvfe exec.jar main_class

运行

java -jar exec.jar

我该怎么做才能使可执行文件有效?

What should I do to make the executable work?

编辑:
我不知道它是否有任何区别,但这是我使用的JDBC驱动程序:

I don't know if it makes any difference, but this is the JDBC driver I use:

https://bitbucket.org/xerial/sqlite-jdbc

推荐答案

您需要将库包含在JAR中。也许您不知道这一点,但JAR文件只是ZIP文件,因此您可以轻松更改其内容。以下是一些如何操作的快速说明。假设您的JAR文件名为 exec.jar ,并且要包含的库(您下载的JAR)的JAR是 driver.jar

You need to include the library inside the JAR. Maybe you don't know this, but JAR files are just ZIP files, so you can change their contents easily. Here are some quick instructions on how to do it. Assuming your JAR file is named exec.jar, and the JAR of the library you want to include (the JAR you downloaded) is driver.jar


  1. 将文件名从 exec.jar 更改为 exec.zip

  2. exec.zip 的所有内容解压缩为文件夹 exec /

  3. 将库文件名从 driver.jar 更改为 driver.zip

  4. driver.zip 的所有内容解压缩到文件夹中 driver /

  5. driver / 的内容复制到 exec / ,但不要复制 META-INF 文件夹。如果弹出窗口询问是否可以合并文件夹,请单击是。

  6. exec / 中的所有文件压缩为 exec.zip

  7. exec.zip 重命名为 exec .jar (替换原文)。

  1. Change your file name from exec.jar to exec.zip.
  2. Extract all the contents of exec.zip into folder exec/
  3. Change your library file name from driver.jar to driver.zip
  4. Extract all the contents of driver.zip into folder driver/
  5. Copy the contents of driver/ into exec/, but do not copy the META-INF folder. If a pop-up asks if it's ok to merge the folders, click yes.
  6. Compress all files in exec/ into exec.zip
  7. Rename exec.zip to exec.jar (replace the original).

您可以使用此方法在JAR中包含任何Java库。

You can include any java library inside a JAR using this method.

这篇关于用sqlite驱动程序jar可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆