private void updatePath(String property, String sep, boolean cp) throws MalformedURLException { String userpath= JMeterUtils.getPropDefault(property,"");// $NON-NLS-1$ if (userpath.length() <= 0) { return; } log.info("{}={}", property, userpath); //$NON-NLS-1$ StringTokenizer tok = new StringTokenizer(userpath, sep); while(tok.hasMoreTokens()) { String path=tok.nextToken(); File f=new File(path); if (!f.canRead() && !f.isDirectory()) { log.warn("Can't read {}", path); } else { if (cp) { log.info("Adding to classpath and loader: {}", path); NewDriver.addPath(path); } else { log.info("Adding to loader: {}", path); NewDriver.addURL(path); } } } }
/** * The main program which actually runs JMeter. * * @param args * the command line arguments */ public static void main(String[] args) { if(!EXCEPTIONS_IN_INIT.isEmpty()) { System.err.println("Configuration error during init, see exceptions:"+exceptionsToString(EXCEPTIONS_IN_INIT)); } else { Thread.currentThread().setContextClassLoader(loader); setLoggingProperties(args); try { Class<?> initialClass = loader.loadClass("org.apache.jmeter.JMeter");// $NON-NLS-1$ Object instance = initialClass.newInstance(); Method startup = initialClass.getMethod("start", new Class[] { new String[0].getClass() });// $NON-NLS-1$ startup.invoke(instance, new Object[] { 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); } } }
private static void setLoggingProperties(String[] args) { String jmLogFile = getCommandLineArgument(args, 'j', "jmeterlogfile");// $NON-NLS-1$ $NON-NLS-2$ if (jmLogFile != null && !jmLogFile.isEmpty()) { jmLogFile = replaceDateFormatInFileName(jmLogFile); System.setProperty("jmeter.logfile", jmLogFile);// $NON-NLS-1$ } else if (System.getProperty("jmeter.logfile") == null) {// $NON-NLS-1$ System.setProperty("jmeter.logfile", "jmeter.log");// $NON-NLS-1$ $NON-NLS-2$ } String jmLogConf = getCommandLineArgument(args, 'i', "jmeterlogconf");// $NON-NLS-1$ $NON-NLS-2$ File logConfFile = null; if (jmLogConf != null && !jmLogConf.isEmpty()) { logConfFile = new File(jmLogConf); } else if (System.getProperty("log4j.configurationFile") == null) {// $NON-NLS-1$ logConfFile = new File("log4j2.xml");// $NON-NLS-1$ if (!logConfFile.isFile()) { logConfFile = new File(JMETER_INSTALLATION_DIRECTORY, "bin" + File.separator + "log4j2.xml");// $NON-NLS-1$ $NON-NLS-2$ } } if (logConfFile != null) { System.setProperty("log4j.configurationFile", logConfFile.toURI().toString());// $NON-NLS-1$ } }
File f = new File(file); if(! (f.exists() && f.canRead())) { f = new File(NewDriver.getJMeterDir() + File.separator + "bin" + File.separator + file); // $NON-NLS-1$ log.info(file + " httpclient parameters does not exist, trying "+f.getAbsolutePath());
/** * Add a URL to the loader classpath only; does not update the system classpath. * * @param path to be added. * @throws MalformedURLException when <code>path</code> points to an invalid url */ public static void addURL(String path) throws MalformedURLException { File furl = new File(path); loader.addURL(furl.toURI().toURL()); // See Java bug 4496398 File[] jars = listJars(furl); for (File jar : jars) { loader.addURL(jar.toURI().toURL()); // See Java bug 4496398 } }
/** * {@inheritDoc} */ @Override public void testStarted() { if (getBasedir() != null && getBasedir().length() > 0) { try { FileServer.getFileServer().setBasedir(FileServer.getFileServer().getBaseDir() + getBasedir()); } catch (IllegalStateException e) { log.error("Failed to set file server base dir with {}", getBasedir(), e); } } // we set the classpath String[] paths = this.getTestPlanClasspathArray(); for (String path : paths) { try { NewDriver.addURL(path); log.info("added {} to classpath", path); } catch (MalformedURLException e) { // TODO Should we continue the test or fail ? log.error("Error adding {} to classpath", path, e); } } }
JMeterUtils.loadJMeterProperties(parser.getArgumentById(PROPFILE_OPT).getArgument()); } else { JMeterUtils.loadJMeterProperties(NewDriver.getJMeterDir() + File.separator + "bin" + File.separator // $NON-NLS-1$ + "jmeter.properties");// $NON-NLS-1$ JMeterUtils.setJMeterHome(NewDriver.getJMeterDir()); } else { JMeterUtils.setJMeterHome(parser.getArgumentById(JMETER_HOME_OPT).getArgument());
/** * Add a directory or jar to the loader and system classpaths. * * @param path * to add to the loader and system classpath * @throws MalformedURLException * if <code>path</code> can not be transformed to a valid * {@link URL} */ public static void addPath(String path) throws MalformedURLException { File file = new File(path); // Ensure that directory URLs end in "/" if (file.isDirectory() && !path.endsWith("/")) {// $NON-NLS-1$ file = new File(path + "/");// $NON-NLS-1$ } loader.addURL(file.toURI().toURL()); // See Java bug 4496398 StringBuilder sb = new StringBuilder(System.getProperty(JAVA_CLASS_PATH)); sb.append(CLASSPATH_SEPARATOR); sb.append(path); File[] jars = listJars(file); for (File jar : jars) { loader.addURL(jar.toURI().toURL()); // See Java bug 4496398 sb.append(CLASSPATH_SEPARATOR); sb.append(jar.getPath()); } // ClassFinder needs this System.setProperty(JAVA_CLASS_PATH,sb.toString()); }