Commit 9184850b authored by Daniel Eggert's avatar Daniel Eggert
Browse files

fixed properties not found bug

parent 7fb99218
package de.potsdam.gfz.gms;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
......@@ -18,7 +22,7 @@ import org.postgis.PGgeometry;
public class DbUtils {
private static final String FILENAME_PROPERTIES = "dbs.properties";
private static final String FILENAME_PROPERTIES = "/dbs.properties";
private static final String OP_TRANSFER_CONFIG = "c";
private static final String OP_SCENE_STATE = "s";
......@@ -98,9 +102,28 @@ public class DbUtils {
return getDbConnection(DEST_DB_PROPS_KEY_PREFIX);
}
private static Connection getDbConnection(String prefix) throws IOException {
private static Properties getProperties() throws IOException {
Properties props = new Properties();
props.load(DbUtils.class.getResourceAsStream("/" + FILENAME_PROPERTIES));
InputStream in = DbUtils.class.getResourceAsStream(FILENAME_PROPERTIES);
if (in == null) {
Path p = Paths.get("." + FILENAME_PROPERTIES);
if (Files.exists(p)) {
in = Files.newInputStream(p);
}
}
if (in == null) {
System.err.println("unable to find " + FILENAME_PROPERTIES.substring(1) + ", put it into the classpath or the same folder as the jar");
System.exit(-1);
}
props.load(in);
return props;
}
private static Connection getDbConnection(String prefix) throws IOException {
Properties props = getProperties();
String host = props.getProperty(prefix + DB_HOST_KEY);
String port = props.getProperty(prefix + DB_PORT_KEY);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment