How to make a portable application (jar + sqlite) in Java?

I made a tiny Java application (yes, tiny, 2 forms and a SQLite database) with Eclipse. It works when I run it in Eclipse.

I will try to export it and make it a portable application (and put it in a usb key), but nothing works.

Here is my code for connecting the database:

DriverManager.getConnection("jdbc:sqlite:"+this.dbName);
DatabaseSQLite ConnBDD = new DatabaseSQLite("BDD/bdd.sqlite")

What should i change?

Here is my diagram under Eclipse

[projects]
src
|-class
lib
|-sqlite-jdbc-3.7.2.jar
BDD
|-database.sqlite
+3
source share
1 answer

When I did this, I did like this:

First put sqlite3.exe in the src / main / resources folder - now sqlite3.exe will be in the jar file as a resource file. Then copy sqlite3.exe (from the JAR) to system32 (if it is not windows and sqlite):

// Copy file SQLite3 into /Windows/System32
try {
    // CopyFromJar just copies file from JAR archive into some directory
    CopyFromJar fileManager = new CopyFromJar();
    fileManager.copyFile(new File("C:\\Windows\\System32\\sqlite3.exe"), "/sqlite3.exe");
} catch (IOException e) {
    ErrorFrame.showException(e);
}

-, sqlite-jdbc . , , :

// Path to database - if first time, then database.db will created in folder with program 
private static final String pathToDatabase = "jdbc:sqlite:database.db";

//..................

// Loading JDBC driver
Class.forName("org.sqlite.JDBC");

// Create connection
Connection con = DriverManager.getConnection(pathToDatabase);
Statement stat = con.createStatement();
-1

All Articles