• Java 1.8+

  • GenRocket Runtime

  • GenRocket UserProfile

Sample Independent Java Code that use Engine API to modify the Scenario at Runtime

import com.genRocket.GenRocketException;
import com.genRocket.engine.EngineAPI;
import com.genRocket.engine.EngineManual;

public class Test {
 Test() {}

 public void execute(String scenarioPath) {
   EngineAPI api = new EngineManual(); // Initializing the EngineAPI

   api.scenarioLoad(scenarioPath); // Loading the scenario file

   String domainName = api.primaryDomain();
   api.domainSetLoopCount(domainName, "100000");

   api.scenarioRun(); // Running the scenario

 public static void main(String[] args) {
   Test test = new Test();
   String scenarioPath = args.length > 0 ? args[0] : null;

   if (scenarioPath == null) {
     throw new GenRocketException("Please specify scenario path in command."); 

   test.execute(scenarioPath); // Calling of execute method
   System.out.println("All Done!");

Directory Structure:

Suppose the file is placed under the directory: C:\Users\ali\javaSource, the GenRocket runtime jars are placed under the directory: %GENROCKET_HOME%/lib


-- genrocket-

-- gr-engine-

-- gr-generators-

-- gr-receivers-



Compilation of Java Source Code using External Jars:

Next step is to compile the java source code using the GenRocket jars which are present in GENROCKET_HOME/lib directory.

In order to do so, we need to execute the following command to compile the source code to create the class file.

By using the defined GenRocket Environment Variable in Linux/Mac

javac -cp $GENROCKET_HOME/lib/*: /home/ali/javaSource/

By using the defined GenRocket Environment Variable in Windows

javac -cp %GENROCKET_HOME%\lib\*; C:\Users\ali\javaSource\

Execution of Java Source Code using External Jars to Run GenRocket Scenario:

After the compilation, change the directory where the compiled class file is created:

cd C:\Users\ali\javaSource

Then, run the java code by providing the classpath of the external jar files to run the GenRocket Scenarios like:

The syntax for Windows:

java -cp <Jar_File_Full_Path>; <ClassName> <GenRocket_Scenario_Full_Path>

The syntax for Linux:

java -cp <Jar_File_Full_Path>: <ClassName> <GenRocket_Scenario_Full_Path>

e.g for Windows. 

java -cp %GENROCKET_HOME%\lib\*; Test "C:\Users\ali\Downloads\UserScenario.grs"

By following the above steps, you’ll be able to run the GenRocket Scenario using Java.