javamavensbtdropwizard

Start Dropwizard with config.yaml from resources


I have a dropwizard question. I use Dropwizard with SBT (which works pretty fine). If I run my application i package it with:

$ sbt clean assembly

And than run the application with:

$ java -jar APPLICATION.jar server

The problem is with this command Dropwizard doesnt load my config file (config.yaml), which is in the resources located. Regarding the Dropwizard Docs I always have to give the config file as parameter like:

$ java -jar APPLICATION.jar server config.yaml

This works fine and it loads the application but is there any possibility to tell Dropwizard to load directly the config.yaml file, because my configuration in the config.yaml file is static and it is always the same. Settings like Database etc which are changing from Server Stage to Server Stage are made as Enviroment Variable which I load with EnvironmentVariableSubstitutor.

Thanks


Solution

  • Use class ResourceConfigurationSourceProvider:

    @Override
    public void initialize(final Bootstrap<ExampleConfiguration> bootstrap) {  
      bootstrap.setConfigurationSourceProvider(new ResourceConfigurationSourceProvider());
      // The rest of initialize...
    }
    

    And then invoke the application like:

    java -jar APPLICATION.jar server /resource-config.yaml

    (note the initial /)