Search code examples
dropwizard

Dropwizard - running a standalone command without adding bundles


I have a Dropwizard app with swagger-jaxrs2 generating a openapi spec. I would like to have a command run this simply as such java -jar app.jar generate build/spec.json for example, but because I have Hibernate configured, it requires me to specify the configuration file even though it is irrelevant to the command completely, and NPEs.

Trying to specify the configuration leads to this error:

unrecognized arguments: 'src/test/resources/configs/configuration.test.yml'

Because I haven't explicitly added the argument for the configuration.

Is there no way around this? I have to specify the config every time? Just really annoying :D


Edit: ended up just hijacking main and outputting it that way since I only need access to the classpath in this instance. Idea courtesy of Dropwizard command line input


Solution

  • You could define a special command extending io.dropwizard.cli.Command, which doesn't require passing configuration as paramater, since it is not a io.dropwizard.cli.ConfiguredCommand. The just register it in your override of io.dropwizard.Application#initialize and call bootstrap.addCommand(new YourSpecialCommand());

    It would allow you to call:
    java -jar app.jar key-of-your-special-command <any args you define in your command>