Question

I have build a Java command line application which consists of several moduls. So when you start the application via the command line, you have to pass one parameter and its options like this for example:

cmd-> java -jar application -startModul1 option1 folderPath 

OR

cmd-> java -jar application -startModul5 500 folderPath 1222 

Currently I have to start each modul by starting the application and passing the requested parameter+options. For now thats finde but later, when I have lets say 20 modules, I want to generate a proccess chain with several moduls started one after the other.

For example at the end I could start both modules from the example above with just one command.

cmd-> java -jar application -startAllModules option1 500 folderPath 1222 

Is there a framework, where I can generate such a proccess chain with existing command line modules? This should not be NOTHING programatically because I want to have some sort of xml-file or whatever, where I just configure a process chain and where I can select the modules and its parameters that should be run with one command.

Was it helpful?

Solution

Have you thought of turning your program into an interpreter?

OTHER TIPS

I think that parsing your command line, understanding what simple commands it must execute (from the xml you want to use) and launching them is enough.

How to launch them?

Process p = Runtime.exec(String[] cmdarray)

where cmdarray will have each of the words of the command:

{"java", "-jar", "application", "-startModul1", "option1", "folderPath"}

and

p.waitFor();

if you want this thread to wait until launched command ends.

Update: non concurrent

The later was in case you want to run several independent processes in parallel. One for command you need.

In case you only need to execute them one after the another there's a more simply way. When the main realizes it must execute multi modules, it calls itself with the appropiate arguments.

public static void main(String[] args) throws Exception {
    // parse params
    if (it's a multi module command line) {
       for (each module you have to execute) {
          main(new String[] {"-startModule1", ..., ...}); // call myself with different args
       }
    }
    else {
       // execute what you've been asked for
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top