Answer the question
In order to leave comments, you need to log in
Why does my program not work as it should when I launch it with a double click?
Hello. The program connects to a remote database. All settings are written in a separate properties file. From IDEA everything works. If I run the assembled project from the command line (I compile, of course, into a jar, and run it like this: java -jar <file name.jar>), everything works too (the data is pulled from the database).
If I launch the program by double-clicking on the jar-nick, then the data from the database is not pulled out. What could it be?
UPD1: I tried it from Windows - everything works. For some reason it doesn't work on Linux (ubuntu).
UPD2: I tried to write the path in the code like this:
private static final String PATH_TO_FILE_PROPERTIES = new File("").getAbsoluteFile() + File.separator + "settings_db_mysql_net.properties";
Answer the question
In order to leave comments, you need to log in
In general, I solved this problem. The result is this method:
private static String getClassLocation(Class<?> c) {
URL pathURL = c.getProtectionDomain().getCodeSource().getLocation();
try {
Path path = Paths.get(pathURL.toURI());
String rootStr = path.getRoot().toString();
return rootStr + path.subpath(0, path.getNameCount()-1).toString() + File.separator;
} catch (URISyntaxException e) {
e.printStackTrace();
return "";
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question