// Find JMeter home dir from the initial classpath String tmpDir; StringTokenizertok=newStringTokenizer(initiaClasspath, File.pathSeparator); if (tok.countTokens() == 1 || (tok.countTokens() == 2// Java on Mac OS can add a second entry to the initial classpath && OS_NAME_LC.startsWith("mac os x")// $NON-NLS-1$ ) ) { Filejar=newFile(tok.nextToken()); try { tmpDir = jar.getCanonicalFile().getParentFile().getParent(); } catch (IOException e) { tmpDir = null; } } else {// e.g. started from IDE with full classpath tmpDir = System.getProperty("jmeter.home","/Users/ylshao/code/github/jmeter");// Allow override $NON-NLS-1$ $NON-NLS-2$ if (tmpDir.length() == 0) { FileuserDir=newFile(System.getProperty("user.dir"));// $NON-NLS-1$ tmpDir = userDir.getAbsoluteFile().getParent(); } } JMETER_INSTALLATION_DIRECTORY=tmpDir; // 获取 jmeter 当前安装目录
publicstaticvoidmain(String[] args) { if(!EXCEPTIONS_IN_INIT.isEmpty()) { System.err.println("Con figuration error during init, see exceptions:"+exceptionsToString(EXCEPTIONS_IN_INIT)); // NOSONAR Intentional System.err use } else { Thread.currentThread().setContextClassLoader(loader);
setLoggingProperties(args);
try { // Only set property if it has not been set explicitely if(System.getProperty(HEADLESS_MODE_PROPERTY) == null && shouldBeHeadless(args)) { System.setProperty(HEADLESS_MODE_PROPERTY, "true"); } Class<?> initialClass = loader.loadClass("org.apache.jmeter.JMeter");// $NON-NLS-1$ Objectinstance= initialClass.getDeclaredConstructor().newInstance(); Methodstartup= initialClass.getMethod("start", newClass[] { newString[0].getClass() });// $NON-NLS-1$ startup.invoke(instance, newObject[] { args }); } catch(Throwable e){ // NOSONAR We want to log home directory in case of exception e.printStackTrace(); // NOSONAR No logger at this step System.err.println("JMeter home directory was detected as: "+JMETER_INSTALLATION_DIRECTORY); // NOSONAR Intentional System.err use } } }