用sqlite驱动程序jar可执行文件 [英] Jar executable with sqlite driver
问题描述
我创建了一个连接到 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
- 将文件名从
exec.jar
更改为exec.zip
。 - 将
exec.zip
的所有内容解压缩为文件夹exec /
- 将库文件名从
driver.jar
更改为driver.zip
- 将
driver.zip
的所有内容解压缩到文件夹中driver /
- 将
driver /
的内容复制到exec /
,但不要复制META-INF
文件夹。如果弹出窗口询问是否可以合并文件夹,请单击是。 - 将
exec /
中的所有文件压缩为exec.zip
- 将
exec.zip
重命名为exec .jar
(替换原文)。
- Change your file name from
exec.jar
toexec.zip
. - Extract all the contents of
exec.zip
into folderexec/
- Change your library file name from
driver.jar
todriver.zip
- Extract all the contents of
driver.zip
into folderdriver/
- Copy the contents of
driver/
intoexec/
, but do not copy theMETA-INF
folder. If a pop-up asks if it's ok to merge the folders, click yes. - Compress all files in
exec/
intoexec.zip
- Rename
exec.zip
toexec.jar
(replace the original).
您可以使用此方法在JAR中包含任何Java库。
You can include any java library inside a JAR using this method.
这篇关于用sqlite驱动程序jar可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!