Reputation: 6198
I am looking for a way to wrap the JMeter CLI using Java. However, I'm stuck on how to both find it and execute it once it's found. On my own user, jmeter
is available on my path. However, when I attempt to execute it like so:
ProcessBuilder processBuilder = new ProcessBuilder("jmeter");
processBuilder.start();
I get:
Exception in thread "main" java.io.IOException: Cannot run program "jmeter": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
at com.vodori.pepper.loadtester.Main.main(Main.java:10)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:135)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.Proc
I'm unsure how best to add jmeter to my path. I can hardcode the path to the JAR on my file system, but I need a portable solution.
I'd also appreciate other workarounds for my situation. Basically, I need to generate mock data for each jmeter run. The data needs to be of many types (e.g., JPEG, PDF, XLS) and the file names need to be traceable per thread. I thought creating a CSV file that points to generated data would be a nice, relatively simple, solution to this problem, but I'm happy to hear alternatives.
Upvotes: 1
Views: 3308
Reputation: 8227
The general approach to finding and running the correct executable is not handled by ProcessBuilder. The approach recommended by these good folks: http://commons.apache.org/proper/commons-exec/, is to invoke a shell with the program you are looking for as the first argument.
Since you have to determine your architecture first and invoke either cmd.exe
or /bin/sh
appropriately, you then pass in jmeter
(or jmeter.bat
) as the first argument, and let the native operating system handle the rest.
Upvotes: 1