Good day. I write my desktop application in Java. I work in IntelliJ IDEA. I ran into a problem after compiling the project in jar, while I was doing Run with the IntelliJ shell, everything was OK. In short, the problem is as follows: I use the FireBird database and the Jaybird-2.2.10 library in my program.

When I run the jar-nickname from the shortcut of this type "java.exe -jar% pathtojarfile%" and enter in the field "Working folder", the one where the jar file actually lies, then when I try to connect from the database I get this error Mistake

I searched the Internet for “java.library.path”, but most of these are straightforward generalists that even “they don’t want to describe this elementary” (something like that). Maybe I was just looking bad or did not understand what Java was asking of me.

Also lay out the code that is responsible for connecting to the database:

import java.io.*; import java.sql.*; import java.util.*; public class FireBirdConnection { public Connection con = null; public Statement stmt; public ResultSet rs; public FireBirdConnection() { String driver = null; String url = null; String login = null; String pass = null; Parameters params = null; try { params = new Parameters(); } catch (FileNotFoundException e) { e.printStackTrace(); } try { url = params.getDataBaseHost(); login = params.getDataBaseUser(); pass = params.getDataBasePassword(); driver = params.getDataBaseDriver(); } catch (Exception ex) { ex.printStackTrace(); } try { Class.forName(driver).newInstance(); con = DriverManager.getConnection(url, login, pass); } catch (ClassNotFoundException ex) { System.err.println("FireBirdConnection.Cannot find this DB driver classes."); ex.printStackTrace(); } catch (SQLException e) { System.err.println("FireBirdConnection.Cannot connect to this DB."); e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } } 

Connection settings are stored in the .properties file of this type:

 DBDRIVER=org.firebirdsql.jdbc.FBDriver ADMINPASSWORD=0095 DBUSER=SYSDBA DBPASS=masterkey DBHOST=jdbc\:firebirdsql\:local\:D\:\\ExamDB\\EXAM.FDB?encoding\=utf8 

If someone pushes with a similar problem, please explain in which direction I should dig or linkanite some adequate article on this topic targeted at an inexperienced specialist. And while I'm going to read about handling exceptions to get away a little :) Thanks in advance.

  • one
    a simple solution is to take all the .dll and .so files from the jaybird delivery, put them in the lib folder in the same directory where the final jar and run something like this: java -Djava.library.path=./lib -jar your_jar.jar . Then make a .bat or .sh file with this command, and so use. - zRrr
  • @zRrr you are right, everything turned out :) I put the files in the lib from the very beginning, but did not know the launch attributes. Thank you so much :) - Viacheslav Zhabonos

0