Search code examples
javamavenconfigurationvert.x

Vertx default configuration file


is there a way how to make vertx load specified default configuration without doing:

java -jar my-fat.jar -conf /path/to/my/conf.json

I mean to make vertx use config file which is present in that my-fat.jar.

For simplicity I would like to have one config by default - maybe could be overriden from outside or maybe not for now. I have lot of microservices that runs independently and separately and I would like to produce them as jars, that are self sufficient.

Can this be done programmatically or maybe with maven?
Thanks for help.


Solution

  • If you're looking into microservices I'd recommend to look into http://vertx.io/docs/vertx-config/java/ as it covers configuration specifically for it. However you're describing that you'd like to override the default config with a preset json, you can quickly achieve this by doing a helper method in these lines of thought:

    public JsonObject config() {
      JsonObject json = Vertx.currentContext().config();
      if (json == null) {
        return new JsonObject(
          vertx.fileSystem()
            .readFileBlocking("Your-Hard-Coded-Fallback.json"));
      }
      return json;
    }
    

    Please note that this is a hack and be aware that you need to have the right context and that the vertx objects needs to be available so it's safe to call this from the start() method. For a proper solution I'd still recommend you to look at the vertx-config module.