Through the command line using -D, the application should receive parameters, for example, such -Dtest="true" or -Dmyarray="one,two,five" (I don’t remember how to correctly specify multiple values). And there are a lot of possible parameters, individually checking each with System.getProperty(...) is not an option, I just need to add them to the filled PropertiesConfiguration (from Apache Commons), for which the logic has already been written (if there are conflicts, priority perperty from the command line).

How to do this with the Apache Commons CLI ? Did not find suitable examples in the network.

  • if too much, maybe you should consider reading from conf.properties ? - Senior Pomidor
  • @Senior Automator there is a sense that there are many possible parameters, only a few of them will be used, and which ones are unknown. A read has already been implemented from the file, but some of the parameters must be redefined directly from the command line - TheSN
  • one
    you read from the file, if from the command line there is the same parameter, then replace, if not. then leave that one out of the file. it all depends on the number of parameters, up to 10-15 you can still pass, and it no longer makes sense. System.getProperty (...) why not an option? - Senior Pomidor
  • @Senior Automator a, tochnyak, something stupid, in principle, the norms approach)) but what if a parameter is set in cmd that is not in the file ... - TheSN
  • we read from the file, then the priority of the parameters, if there is already such - we replace. if not, add a new one, then from the environment in the same way. The main thing with priorities to understand. I offer a file - environment - parameters - Senior Pomidor

0