user3653831
user3653831

Reputation: 235

Jar executable with sqlite driver

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

Answers (2)

Zenadix
Zenadix

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

  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).

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

Upvotes: 2

djangofan
djangofan

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

Related Questions