* Takes the command line arguments and uses them to determine how to
* startup JMeter.
*/
public void start(String[] args) {
CLArgsParser parser = new CLArgsParser(args, options);
String error = parser.getErrorString();
if (error == null){// Check option combinations
boolean gui = parser.getArgumentById(NONGUI_OPT)==null;
boolean remoteStart = parser.getArgumentById(REMOTE_OPT)!=null
|| parser.getArgumentById(REMOTE_OPT_PARAM)!=null;
if (gui && remoteStart) {
error = "-r and -R are only valid in non-GUI mode";
}
}
if (null != error) {
System.err.println("Error: " + error);
System.out.println("Usage");
System.out.println(CLUtil.describeOptions(options).toString());
return;
}
try {
initializeProperties(parser); // Also initialises JMeter logging
/*
* The following is needed for HTTPClient.
* (originally tried doing this in HTTPSampler2,
* but it appears that it was done too late when running in GUI mode)
* Set the commons logging default to Avalon Logkit, if not already defined
*/
if (System.getProperty("org.apache.commons.logging.Log") == null) { // $NON-NLS-1$
System.setProperty("org.apache.commons.logging.Log" // $NON-NLS-1$
, "org.apache.commons.logging.impl.LogKitLogger"); // $NON-NLS-1$
}
log.info(JMeterUtils.getJMeterCopyright());
log.info("Version " + JMeterUtils.getJMeterVersion());
logProperty("java.version"); //$NON-NLS-1$
logProperty("java.vm.name"); //$NON-NLS-1$
logProperty("os.name"); //$NON-NLS-1$
logProperty("os.arch"); //$NON-NLS-1$
logProperty("os.version"); //$NON-NLS-1$
logProperty("file.encoding"); // $NON-NLS-1$
log.info("Default Locale=" + Locale.getDefault().getDisplayName());
log.info("JMeter Locale=" + JMeterUtils.getLocale().getDisplayName());
log.info("JMeterHome=" + JMeterUtils.getJMeterHome());
logProperty("user.dir"," ="); //$NON-NLS-1$
log.info("PWD ="+new File(".").getCanonicalPath());//$NON-NLS-1$
log.info("IP: "+JMeterUtils.getLocalHostIP()
+" Name: "+JMeterUtils.getLocalHostName()
+" FullName: "+JMeterUtils.getLocalHostFullName());
setProxy(parser);
updateClassLoader();
if (log.isDebugEnabled())
{
String jcp=System.getProperty("java.class.path");// $NON-NLS-1$
String bits[] =jcp.split(File.pathSeparator);
log.debug("ClassPath");
for(int i = 0; i<bits.length ;i++){
log.debug(bits[i]);
}
log.debug(jcp);
}
// Set some (hopefully!) useful properties
long now=System.currentTimeMillis();
JMeterUtils.setProperty("START.MS",Long.toString(now));// $NON-NLS-1$
Date today=new Date(now); // so it agrees with above
// TODO perhaps should share code with __time() function for this...
JMeterUtils.setProperty("START.YMD",new SimpleDateFormat("yyyyMMdd").format(today));// $NON-NLS-1$ $NON-NLS-2$
JMeterUtils.setProperty("START.HMS",new SimpleDateFormat("HHmmss").format(today));// $NON-NLS-1$ $NON-NLS-2$
if (parser.getArgumentById(VERSION_OPT) != null) {
System.out.println(JMeterUtils.getJMeterCopyright());
System.out.println("Version " + JMeterUtils.getJMeterVersion());
} else if (parser.getArgumentById(HELP_OPT) != null) {
System.out.println(JMeterUtils.getResourceFileAsText("org/apache/jmeter/help.txt"));// $NON-NLS-1$
} else if (parser.getArgumentById(SERVER_OPT) != null) {
// We need to check if the JMeter home contains spaces in the path,
// because then we will not be able to bind to RMI registry, see
// Java bug id 4496398
final String jmHome = JMeterUtils.getJMeterHome();
if(jmHome.indexOf(" ") > -1) {// $NON-NLS-1$
// Just warn user, and exit, no reason to continue, since we will
// not be able to bind to RMI registry, until Java bug 4496398 is fixed
log.error("JMeter path cannot contain spaces when run in server mode : " + jmHome);
throw new RuntimeException("JMeter path cannot contain spaces when run in server mode: "+jmHome);
}
// Start the server
startServer(JMeterUtils.getPropDefault("server_port", 0));// $NON-NLS-1$
startOptionalServers();
} else {
String testFile=null;
CLOption testFileOpt = parser.getArgumentById(TESTFILE_OPT);
if (testFileOpt != null){
testFile = testFileOpt.getArgument();
if (USE_LAST_JMX.equals(testFile)) {
testFile = LoadRecentProject.getRecentFile(0);// most recent
}
}
if (parser.getArgumentById(NONGUI_OPT) == null) {
startGui(testFile);
startOptionalServers();
} else {
CLOption rem=parser.getArgumentById(REMOTE_OPT_PARAM);
if (rem==null) { rem=parser.getArgumentById(REMOTE_OPT); }
CLOption jtl = parser.getArgumentById(LOGFILE_OPT);
String jtlFile = null;
if (jtl != null){
jtlFile=processLAST(jtl.getArgument(), ".jtl"); // $NON-NLS-1$
}
startNonGui(testFile, jtlFile, rem);