Merge pull request #31 from informatik-ag-ngl/f/improved_config
Loading config from properties before command line args
This commit is contained in:
commit
363aa1a889
@ -32,7 +32,7 @@ public class Config {
|
|||||||
*
|
*
|
||||||
* @param properties a {@link Properties} object containing information about
|
* @param properties a {@link Properties} object containing information about
|
||||||
* the server and port, as well as the path to the local
|
* the server and port, as well as the path to the local
|
||||||
* database
|
* database and the synchronization timeout
|
||||||
* @since Envoy v0.1-alpha
|
* @since Envoy v0.1-alpha
|
||||||
*/
|
*/
|
||||||
public void load(Properties properties) {
|
public void load(Properties properties) {
|
||||||
@ -64,8 +64,6 @@ public class Config {
|
|||||||
case "-db":
|
case "-db":
|
||||||
localDB = new File(args[++i]);
|
localDB = new File(args[++i]);
|
||||||
}
|
}
|
||||||
if (localDB == null) localDB = new File(".\\localDB");
|
|
||||||
if (syncTimeout == 0) syncTimeout = 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,9 +26,8 @@ public class Startup {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Config config = Config.getInstance();
|
Config config = Config.getInstance();
|
||||||
if (args.length > 0) {
|
|
||||||
config.load(args);
|
// Load the configuration from client.properties first
|
||||||
} else {
|
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||||
try {
|
try {
|
||||||
Properties configProperties = new Properties();
|
Properties configProperties = new Properties();
|
||||||
@ -37,10 +36,14 @@ public class Startup {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Override configuration values with command line arguments
|
||||||
|
if (args.length > 0)
|
||||||
|
config.load(args);
|
||||||
|
|
||||||
if (!config.isInitialized()) {
|
if (!config.isInitialized()) {
|
||||||
System.err.println("Server or port are not defined. Exiting...");
|
JOptionPane.showMessageDialog(null, "Error loading configuration values.", "Configuration error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +60,7 @@ public class Startup {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
JOptionPane.showMessageDialog(null,
|
JOptionPane.showMessageDialog(null,
|
||||||
"Error while loading local database: " + e.toString() + "\nChats will not be stored locally.",
|
"Error while loading local database: " + e.toString() + "\nChats will not be stored locally.",
|
||||||
"Local DB error",
|
"Local DB error", JOptionPane.WARNING_MESSAGE);
|
||||||
JOptionPane.WARNING_MESSAGE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EventQueue.invokeLater(() -> {
|
EventQueue.invokeLater(() -> {
|
||||||
|
Reference in New Issue
Block a user