I want to distribute a Java application that connects to an external database using a Java properties file. My issue is that once my project is exported as a Jar file (and then as an EXE using Launch4j) in a different place than my project's root folder, the connection to my database fails and most of my pictures are not loaded.
Regarding just the connection, I have tried several things to read the connection properties written in an external file, which is located in a source folder :
The code :
I also tried to let the property file in the root folder of my project: both way work when running the project, but fail when launching the jar or the exe.
First I thought it was just because of the exportation of my project, that maybe failed due to some wrong settings. But I am started to think that I may have a wrong understanding on how to import resources into a Java project, even thought I followed several topics on that subject on Stackoverflow.
So :
As the connection file contains some sensible data (ie. the password to connect to the database), I hoped there was an official way to keep that file protected from unwanted access after exporting the Jar/exe file.
Thank you a lot for helping. I can provide more code and pictures if needed.
Resources (as in a jar) are not File (on the file system). Use
getClass().getResourceAsStream("/conf/connexxion.properties");`
For that place the conf
under /resources
.