Mike,

I attach a unidiff of changes (mainly) to NewDriver.jar that enable 
JMeter to be invoked without having /bin as the working directory. It 
also fixes the log4j initialisation problem.

Note: the search_paths= in jmeter.properties are now interpreted 
relative to the JMeter base directory, so they are search_paths=lib/ext 
and not serach_paths=../lib/ext

I have tested the changes on Linux, but not Windows.

//derek

Mike Stover wrote:

>Derek,
>     Glad to see the problem was easily solved.  Regarding setting the Threads 
>ContextClassLoader - I've already done that in the latest CVS.  I needed to do it 
>because of 
>the way the SAX factory finds a parser implementation.
>
>However, I will look at adding only .jar files - I guess I thought I did that, but 
>guess I overlooked 
>it.  I would like to see your changes regarding log4j and correct initialization when 
>/bin is not 
>the working directory.
>
>-Mike
>
>  
>



________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
Index: bin/jmeter.properties
===================================================================
RCS file: /home/cvspublic/jakarta-jmeter/bin/jmeter.properties,v
retrieving revision 1.38
diff -u -r1.38 jmeter.properties
--- bin/jmeter.properties       23 May 2002 15:47:03 -0000      1.38
+++ bin/jmeter.properties       11 Jul 2002 02:06:55 -0000
@@ -2,7 +2,7 @@
 # Apache JMeter Property file
 ################################################################################
 #Paths to search for classes (";" must be the separator)
-search_paths=../lib/ext
+search_paths=lib/ext
 
 # Netscape HTTP Cookie file
 cookies=cookies
Index: src_1/org/apache/jmeter/JMeter.java
===================================================================
RCS file: /home/cvspublic/jakarta-jmeter/src_1/org/apache/jmeter/JMeter.java,v
retrieving revision 1.3
diff -u -r1.3 JMeter.java
--- src_1/org/apache/jmeter/JMeter.java 13 Jun 2002 00:45:15 -0000      1.3
+++ src_1/org/apache/jmeter/JMeter.java 11 Jul 2002 02:06:56 -0000
@@ -191,8 +191,8 @@
                if (parser.getArgumentById(PROPFILE_OPT) != null) {
                        
JMeterUtils.getProperties(parser.getArgumentById(PROPFILE_OPT).getArgument());
                } else {
-                       JMeterUtils.getProperties(
-                               System.getProperty("user.dir") + File.separator + 
"jmeter.properties");
+                       JMeterUtils.getProperties(NewDriver.getJMeterDir() +
+                               File.separator + "bin" + File.separator + 
+"jmeter.properties");
                }
        }
 
@@ -295,4 +295,4 @@
        private static void println(String str) {
                System.out.println(str);
        }
-}
\ No newline at end of file
+}
Index: src_1/org/apache/jmeter/NewDriver.java
===================================================================
RCS file: /home/cvspublic/jakarta-jmeter/src_1/org/apache/jmeter/NewDriver.java,v
retrieving revision 1.9
diff -u -r1.9 NewDriver.java
--- src_1/org/apache/jmeter/NewDriver.java      11 Jul 2002 00:26:52 -0000      1.9
+++ src_1/org/apache/jmeter/NewDriver.java      11 Jul 2002 02:06:58 -0000
@@ -56,15 +56,14 @@
 
 import java.io.File;
 import java.io.FilenameFilter;
+import java.io.IOException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.LinkedList;
 import java.util.List;
-
-import sun.security.krb5.internal.i;
-import sun.security.krb5.internal.crypto.e;
+import java.util.StringTokenizer;
 
 
 
@@ -80,54 +79,65 @@
 public class NewDriver
 {
        private static URLClassLoader loader;   
-       
+       private static String jmDir;
 
-       
        static {
-               List jars = new LinkedList();
-               String jmDir = System.getProperty("user.dir")+File.separator+"..";
-               File libDir = new File(jmDir+File.separator+"lib");
-               File extDir = new 
File(jmDir+File.separator+"lib"+File.separator+"ext");
-               File[] libJars = libDir.listFiles(new FilenameFilter() {
-                       public boolean accept(File dir,String name) {
-                               if(name.endsWith(".jar"))
-                                       return true;
-                               return false;
-                       }});
-               File[] extJars = extDir.listFiles(new FilenameFilter() {
-                       public boolean accept(File dir,String name) {
-                               if(name.endsWith(".jar"))
-                                       return true;
-                               return false;
-                       }});
-               StringBuffer classpath = new StringBuffer();
-               for(int i = 0;i < libJars.length;i++)
-               {
-                       try
-                       {
-                               jars.add(new URL("file","",libJars[i].getPath()));
-                               classpath.append(System.getProperty("path.separator"));
-                               classpath.append(libJars[i].getPath());
-                       }
-                       catch(MalformedURLException e)
-                       {
-                               e.printStackTrace();
+               // determine the JMeter installation directory
+               // if we were invoked like this:
+               // "java -jar $jmDir/bin/ApacheJMeter.jar"
+               // then classpath only contains one element,
+               // from which we can calculate jmDir.
+
+               String cp = System.getProperty("java.class.path");
+               StringTokenizer tok = new StringTokenizer(cp, File.pathSeparator);
+
+               if (tok.countTokens() == 1) {
+                       File jar = new File(tok.nextToken());
+                       try {
+                               jmDir = 
+jar.getCanonicalFile().getParentFile().getParent();
+                       } catch (IOException e) {
                        }
                }
-               for(int i = 0;i < extJars.length;i++)
+               if (jmDir == null) {
+                       File userDir = new File(System.getProperty("user.dir"));
+                       jmDir = userDir.getAbsoluteFile().getParent();
+               }
+
+               String[] dirs = {
+                       "lib",
+                       "lib" + File.separator + "ext"
+               };
+
+               List jars = new LinkedList();
+               StringBuffer classpath = new StringBuffer();
+
+               for (int j = 0; j < dirs.length; j++)
                {
-                       try
-                       {
-                               jars.add(new URL("file","",extJars[i].getPath()));
-                               classpath.append(System.getProperty("path.separator"));
-                               classpath.append(extJars[i].getPath());
-                       }
-                       catch(MalformedURLException e)
+                       File dir = new File(jmDir, dirs[j]);
+                       File[] files = dir.listFiles(new FilenameFilter() {
+                           public boolean accept(File dir, String name)
+                           {
+                                   return name.endsWith(".jar");
+                           }
+                       });
+                       
+                       for (int i = 0; i < files.length; i++)
                        {
-                               e.printStackTrace();
+                               try
+                               {
+                                       jars.add(files[i].toURL());
+                                       classpath.append(File.pathSeparator);
+                                       classpath.append(files[i].getPath());
+                               }
+                               catch(MalformedURLException e)
+                               {
+                                       e.printStackTrace();
+                               }
                        }
                }
+
                
System.setProperty("java.class.path",System.getProperty("java.class.path")+classpath.toString());
+
                loader = new URLClassLoader((URL[])jars.toArray(new URL[0]));
                try {
                        loader.loadClass("org.apache.jmeter.gui.GuiPackage");
@@ -152,6 +162,11 @@
                
        }
 
+       public static String getJMeterDir()
+       {
+               return jmDir;
+       }
+
        /************************************************************
         *  The main program for the NewDriver class
         *
@@ -159,9 +174,14 @@
         ***********************************************************/
        public static void main(String[] args)
        {       
+               if (System.getProperty("log4j.configuration") == null)
+               {
+                       File conf = new File(jmDir, "bin" + File.separator + 
+"log4j.conf");
+                       System.setProperty("log4j.configuration", "file:" + conf);
+               }
+
                Thread.currentThread().setContextClassLoader(loader);
-               
System.setProperty("log4j.configuration",System.getProperty("user.dir")+
-                               File.separator+"log4j.conf");
+
                        try {
                                Class JMeter = 
loader.loadClass("org.apache.jmeter.JMeter");
                                Object instance = JMeter.newInstance();
Index: src_1/org/apache/jmeter/util/ClassFinder.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jmeter/src_1/org/apache/jmeter/util/ClassFinder.java,v
retrieving revision 1.5
diff -u -r1.5 ClassFinder.java
--- src_1/org/apache/jmeter/util/ClassFinder.java       23 May 2002 15:47:07 -0000     
 1.5
+++ src_1/org/apache/jmeter/util/ClassFinder.java       11 Jul 2002 02:07:00 -0000
@@ -112,6 +112,7 @@
 import java.lang.reflect.Modifier;
 import junit.framework.TestCase;
 import org.apache.log4j.*;
+import org.apache.jmeter.NewDriver;
 /************************************************************
 
  *  This class finds classes that implement one or more specified interfaces.
@@ -206,8 +207,19 @@
                List listSuperClasses = null;
                String[] strPathsOrJars =
                        JMeterUtils.split(
-                               JMeterUtils.getPropDefault("search_paths", 
".;ApacheJMeter_core.jar"),
+                               JMeterUtils.getPropDefault("search_paths", "lib/ext"),
                                ";");
+
+               // paths are relative to jmDir - convert to absolute
+               for (int i = 0; i < strPathsOrJars.length; i++) {
+                       File file = new File(strPathsOrJars[i]);
+                       if (!file.isAbsolute()) {
+                               file = new File(NewDriver.getJMeterDir(),
+                                       strPathsOrJars[i]);
+                               strPathsOrJars[i] = file.getPath();
+                       }
+               }
+
                strPathsOrJars = addJarsInPath(strPathsOrJars);
                if (catClass.isDebugEnabled()) {
                        for (int k = 0; k < strPathsOrJars.length; k++) {
@@ -815,4 +827,4 @@
                        }
                }
        }
-}
\ No newline at end of file
+}

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to