Reputation: 235
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.
If I do:
jar cvfe exec.jar main_class
I will get "class not found: org.sqlite.JDBC" when running with
java -jar exec.jar
What should I do to make the executable work?
Edit: I don't know if it makes any difference, but this is the JDBC driver I use:
https://bitbucket.org/xerial/sqlite-jdbc
Upvotes: 1
Views: 1121
Reputation: 16279
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
to exec.zip
.exec.zip
into folder exec/
driver.jar
to driver.zip
driver.zip
into folder driver/
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.exec/
into exec.zip
exec.zip
to exec.jar
(replace the original).You can include any java library inside a JAR using this method.
Upvotes: 2
Reputation: 29689
Here is the doc:
C:\Windows\System32>jar /?
Illegal option: /
Usage: jar {ctxui}[vfmn0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
And so I think the command you need is:
jar cvfe exec.jar main_class main_class
Upvotes: 0