4. Run solution with arguments

Top  Previous  Next

When one has a project with many simulations (i. e. lines in the project data file) that takes very long to simulate, it is convenient to be able to run only subsets of the project.

Especially during the testing period one wants to run different combinations. Instead of hard-coding it into the application, one can submit the selected lines as command line parameters to the application.

 

The application takes as an argument a string with the project lines.

 

The main method always gets as parameter an array of strings, containing arguments submitted by the user when calling the program.

 

First one checks whether the array has a length greater than zero, that means that the user has submitted at least one argument.

 

Then the first argument (with index 0, as Java starts counting from 0) is passed to the variable tProjectLines. Later one calls the method:

         

         runSimulation(tSolutionFileName, tProjectFileName, tProjectLines);

 

which takes the project lines string additionally to the solution and project file name.

 

 

Just add the argument after the program, e.g.

         java net.simplace.sim.runs.SimulationExperimentTemplate.Lintul5ProjectRunArgument 1,3-5,7

 

From Eclipse

 

   Select from the main menu Run -> Run Configurations ...

   Enter a name for the configuration (e.g. the name of the class)

   On the panel (c) Main enter the main class, e.g. net.simplace.sim.runs.SimulationExperimentTemplate.Lintul5ProjectRunArgument

   Switch to the panel (x)= Arguments and enter the program arguments e.g. 1,3-5,7

   Click on Apply and then Run

 

Task 4.1 Take simplace_run/simulation/SimulationExperimentTemplate/solution/Lintul5.sol.xml and  simplace_run/simulation/SimulationExperimentTemplate/solution/Lintul5All.proj.xml and try to run them using a meaningful argument.

 

Hints: See the following example

 

 package net.simplace.sim.runs.SimulationExperimentTemplate;

 import net.simplace.sim.runs.SimplacerunStandardRun;

 public class Lintul5ProjectRunSelected extends SimplacerunStandardRun

 {

                    public static void main(String[] args)

                    {

                        String tProjectLines = null;

                        if(args.length>0)

                        {

                            tProjectLines=args[0];

                        }

 

                        String tSolutionFileName = "${_WORKDIR_}/SimulationExperimentTemplate/solution/Lintul5.sol.xml";

                        String tProjectFileName = "${_WORKDIR_}/SimulationExperimentTemplate/project/Lintul5All.proj.xml";

 

                        setUp();

                        runSimulation(tSolutionFileName, tProjectFileName, tProjectLines);

                        showMessage("finished Run of Lintul5 Project ");

                        exit();

                    }

 }

 

Solution: Open the simplace_run/runs/net/simplace/sim/runs/SimulationExperimentTemplate/Lintul5ProjectRunArgument.java to see how it should be done.

 

 

*SimulationProjects are found in simplace_modules\test\training\solution\2_WorkingWithProjects