0

I am new in java development. Creating demo project using java + javafx + maven in eclipse it is working fine and able to connect embedded database sqlite and run query easily. But when I created build through jpackager following commands

project location > mvn clean

mvn package

sh/link.sh -e

sh/create-appimage.sh -e

Successfully created mac build when I run this javafx screen comes out but it's not table to connect org.sqlite.JDBC. It gives Exception java.lang.ClassNotFoundException: org.sqlite.JDBC. I have checked maven pom.xml file that already added sqlite jar file. Please help me. Is any thing I am missing or in deployment this JDBC driver will not work ? Is there any other method to connect ?

JDBC configuration in my code is

static final String JDBC_DRIVER = "org.sqlite.JDBC";
static final String DB_URL = "jdbc:sqlite:src/main/resources/example.db";

public static Connection getConnection()  {
    Connection conn = null;

        // STEP 2: Register jdbc drive

        Class.forName(JDBC_DRIVER);

        // STEP 3 : Open a connetion

        System.out.println("connecting to database....");

        conn = DriverManager.getConnection(DB_URL);
        return conn;
    }
Smile
  • 3,832
  • 3
  • 25
  • 39
Anil
  • 1
  • 1
  • did you add it to the pom.xml like a dependency, or like a librery jar? – tino89 May 13 '20 at 04:41
  • Yes, I added in pom.xml like org.xerial sqlite-jdbc 3.30.1 – Anil May 13 '20 at 04:49
  • try setting this version, 3.15.1 – tino89 May 13 '20 at 05:02
  • Same error, No change. – Anil May 13 '20 at 05:25
  • I think your problem is that when you compile and run you are not adding your dependencies to the class path, or it doesn't know about them. When maven builds the jar it doesn't include the dependencies in the build - at least not automatically from my experience. You want something like this: https://stackoverflow.com/questions/11758594/how-do-i-put-all-required-jar-files-in-a-library-folder-inside-the-final-jar-fil At least that would explain it working in eclipse and not after mvn clean install – Damian Willmer May 13 '20 at 13:28
  • you get sure, when you add a dependecy it must be like that provided or without this tag – tino89 May 13 '20 at 14:21
  • Thank you. I have also tried with scope tag. I think @DamianWillmer saying right it is related to maven dependency and I missing some plugin which also add sqlite in build. I will try and let you know if it works. Thanks – Anil May 13 '20 at 16:37
  • I have tried by many ways as well as to ensure sqlite jar is inside jar or not So I run command jar tf example.jar and found file here lib/sqlite-jdbc-3.30.1.jar but problem is same ( org.sqlite.JDBC class not found ). – Anil May 16 '20 at 01:49
  • share me your code, if it is posible! – tino89 May 16 '20 at 05:11
  • Here is code https://drive.google.com/file/d/1YoYUGb16wqin7G1l6q8V9eV2G1CvJzIX/view?usp=sharing – Anil May 16 '20 at 16:45
  • You might not be able to add the dependency in the jar itself, but maybe point to a lib folder on the drive somewhere? that when it starts up it can load the lib? alternetavely you can add the required jar to the classpath when you run it i.e java.exe -classpath E:\lib\* Main or something of that sort. Though looking at your pom.xml i think you miss understood what the previous link was saying – Damian Willmer May 20 '20 at 09:25

0 Answers0