TomEE embedded will support, with the version 7.0.2, several overrides through the options of TomEEEmbeddedApplicationRunner. For instance, to change the server http port, you will be able to do:

java -jar mycli.jar --tomee.embedded.application.runner.http=9090

This is great but when writing you own main embedding TomEE embedded you can desire to handle your own options and provide to your end use something like:

java -jar mycli.jar --tomee.embedded.application.runner.http=9090 \
    --app-configuration=/opt/app/config.properties \
    --app-proxy=http://localhost:1234 \
    ....

TomEE Embedded sets in OpenEJB SystemInstance component the arguments of the main() so you can receive it this way:

String[] args = SystemInstance.get().getComponent(TomEEEmbeddedArgs.class).getArgs();

But with TomEEEmbeddedApplicationRunner you can also just inject them in the application class:

@Application
public class MyApp {
    @TomEEEmbeddedApplicationRunner.Args
    private String[] args;

    @Inject
    private Configuration configuration;

    @PostConstruct
    public void loadConfig() {
        configuration.loadFromCli(args);
    }
}

The @Args annotation makes it easier to read it and the @Application lifecycle support (@PostConstruct) makes it very smooth to integrate with the application.

Note that the args value also contains TomEE custom properties to let you read it if you need (avoids to redefine the same property if you need the port for instance which would lead to duplicating the configuration). This means that your loadFromCli() method shouldn't fail cause it encouters unknown properties or that you need to clean up these properties before passing them to the method.

Before that feature, custom integrations were either wrapping the whole main to own the configuration or using system properties. First solution had the drawback to often lack some tomee properties wiring and second one had the one to not let you handle a proper help command and as letting your users rely on a plain old documentation to know what they can do which was also implying you needed to write and maintain this doc where a small CLI can avoid all this work.

From the same author:

In the same category: