3

I'm using gradle with the javafx-gradle plugin to produce a self-contained javafx application using the task "jfxDeploy".

I have the following directory structure:

|-- src
|    |-- main
|         |-- java
|         |     \-- Main.java
|         |-- resources
|               \-- database_config.properties

I'm loading the database configuration with the apache-commons-configuration and use its information to connect to to a database (information = port, ip - normal database stuff):

public static DBConnectionParameters getConfigDBConnectionParameters() {
    try {
        InetAddress ip = InetAddress.getByName(getProperty("configIP"));
        String port = getProperty("configPort");
        return new DBConnectionParameters(ip, port);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return null;
}

After creating the self-contained application the build directory contains my program which is now startable using the .exe. The directory structure looks like that:

|-- AppName
|    |-- app
|         \-- externalJars.jar
|    |-- runtime\...
|    \-- AppName.exe
|    \-- AppName.ico

Starting the program, reading the database configuration and connecting to the database works fine, but: I need to be able to change the database_config.properties every now and then. But since I now got my self-contained app, the file is not accessible anymore. So, i need a editable file for configuring my parameters - while at the same time using a self-contained application. To prevent misunderstanding: the configuration file does not need read protection. What i need is (and it's perfectly fine) the file just laying in the application folder (or a subdirectory).

I like to keep my applications dynamic - and a little file for fast configuration is perfect for achieving that. How to do it?

JohnSmith
  • 33
  • 6
  • What I've seen is: multiple configuration files. The default comes with your distribution. An installation may add another one, containing a subset overriding the default. A user may have yet another one, overriding default+installation, perhaps in his home directory. And command line parameters may provide yet another level, overriding individually for an execution of your app. – laune Feb 16 '15 at 08:44
  • So you're saying look for a config file in say "./app/configfiles" and if nothing is there, use the built-in config-file? This should be feasible via a simple gradle task that launches after the deploy task i think? – JohnSmith Feb 16 '15 at 09:09
  • 1
    You define the order the files a read - whatever makes more sense. I think that reading *all* of them - default, installation, user, command line - is the best as definitions in later files can override earlier ones. – laune Feb 16 '15 at 11:51

0 Answers0