View | Details | Raw Unified | Return to bug 55503
Collapse All | Expand All

(-)src/core/org/apache/jmeter/JMeter.java (-9 / +15 lines)
Lines 403-413 Link Here
403
403
404
    // Update classloader if necessary
404
    // Update classloader if necessary
405
    private void updateClassLoader() {
405
    private void updateClassLoader() {
406
            updatePath("search_paths",";"); //$NON-NLS-1$//$NON-NLS-2$
406
            updatePath("search_paths",";", true); //$NON-NLS-1$//$NON-NLS-2$
407
            updatePath("user.classpath",File.pathSeparator);//$NON-NLS-1$
407
            updatePath("user.classpath",File.pathSeparator, true);//$NON-NLS-1$
408
            updatePath("plugin_dependency_paths",";", false);//$NON-NLS-1$
408
    }
409
    }
409
410
410
    private void updatePath(String property, String sep) {
411
    private void updatePath(String property, String sep, boolean cp) {
411
        String userpath= JMeterUtils.getPropDefault(property,"");// $NON-NLS-1$
412
        String userpath= JMeterUtils.getPropDefault(property,"");// $NON-NLS-1$
412
        if (userpath.length() <= 0) { return; }
413
        if (userpath.length() <= 0) { return; }
413
        log.info(property+"="+userpath); //$NON-NLS-1$
414
        log.info(property+"="+userpath); //$NON-NLS-1$
Lines 418-428 Link Here
418
            if (!f.canRead() && !f.isDirectory()) {
419
            if (!f.canRead() && !f.isDirectory()) {
419
                log.warn("Can't read "+path);
420
                log.warn("Can't read "+path);
420
            } else {
421
            } else {
421
                log.info("Adding to classpath: "+path);
422
                if (cp) {
422
                try {
423
                    log.info("Adding to classpath and loader: "+path);
423
                    NewDriver.addPath(path);
424
                    try {
424
                } catch (MalformedURLException e) {
425
                        NewDriver.addPath(path);
425
                    log.warn("Error adding: "+path+" "+e.getLocalizedMessage());
426
                    } catch (MalformedURLException e) {
427
                        log.warn("Error adding: "+path+" "+e.getLocalizedMessage());
428
                    }
429
                } else {
430
                    log.info("Adding to loader: "+path);
431
                    NewDriver.addURL(path);
426
                }
432
                }
427
            }
433
            }
428
        }
434
        }
Lines 1175-1178 Link Here
1175
1181
1176
        return socket;
1182
        return socket;
1177
    }
1183
    }
1178
}
1184
}
(-)src/core/org/apache/jmeter/NewDriver.java (+41 lines)
Lines 141-146 Link Here
141
    }
141
    }
142
142
143
    /**
143
    /**
144
     * Generate an array of jar files located in a directory.
145
     * Jar files located in sub directories will not be added.
146
     *
147
     * @param dir to search for the jar files.
148
     */
149
    private static File[] listJars(File dir) {
150
        if (dir.isDirectory()) {
151
            return dir.listFiles(new FilenameFilter() {
152
                @Override
153
                public boolean accept(File f, String name) {
154
                    if (name.endsWith(".jar")) {// $NON-NLS-1$
155
                        File jar = new File(f, name);
156
                        return jar.isFile() && jar.canRead();
157
                    }
158
                    return false;
159
                }
160
            });
161
        }
162
        return new File[0];
163
    }
164
165
    /**
144
     * Add a URL to the loader classpath only; does not update the system classpath.
166
     * Add a URL to the loader classpath only; does not update the system classpath.
145
     *
167
     *
146
     * @param path to be added.
168
     * @param path to be added.
Lines 152-157 Link Here
152
        } catch (MalformedURLException e) {
174
        } catch (MalformedURLException e) {
153
            e.printStackTrace();
175
            e.printStackTrace();
154
        }
176
        }
177
        File[] jars = listJars(furl);
178
        for (int x = 0; x < jars.length; x++) {
179
            try {
180
                loader.addURL(jars[x].toURI().toURL()); // See Java bug 4496398
181
            } catch (MalformedURLException e) {
182
                e.printStackTrace();
183
            }
184
        }
155
    }
185
    }
156
186
157
    /**
187
    /**
Lines 179-184 Link Here
179
        StringBuilder sb = new StringBuilder(System.getProperty(JAVA_CLASS_PATH));
209
        StringBuilder sb = new StringBuilder(System.getProperty(JAVA_CLASS_PATH));
180
        sb.append(CLASSPATH_SEPARATOR);
210
        sb.append(CLASSPATH_SEPARATOR);
181
        sb.append(path);
211
        sb.append(path);
212
        File[] jars = listJars(file);
213
        for (int x = 0; x < jars.length; x++) {
214
            try {
215
                loader.addURL(jars[x].toURI().toURL()); // See Java bug 4496398
216
                sb.append(CLASSPATH_SEPARATOR);
217
                sb.append(jars[x].getPath());
218
            } catch (MalformedURLException e) {
219
                e.printStackTrace();
220
            }
221
        }
222
182
        // ClassFinder needs this
223
        // ClassFinder needs this
183
        System.setProperty(JAVA_CLASS_PATH,sb.toString());
224
        System.setProperty(JAVA_CLASS_PATH,sb.toString());
184
    }
225
    }
(-)bin/jmeter.properties (-9 / +29 lines)
Lines 912-929 Link Here
912
# Classpath configuration
912
# Classpath configuration
913
#---------------------------------------------------------------------------
913
#---------------------------------------------------------------------------
914
914
915
# List of paths (separated by ;) to search for additional JMeter extension classes
915
# List of paths (separated by ;) to search for additional JMeter plugin classes,
916
# - for example new GUI elements and samplers
916
# for example new GUI elements and samplers.
917
# These are in addition to lib/ext. Do not use this for utility jars.
917
# A path item can either be a jar file or a directory.
918
# Any jar file in such a directory will be automatically included,
919
# jar files in sub directories are ignored.
920
# The given value is in addition to any jars found in the lib/ext directory.
921
# Do not use this for utility ir plugin dependecy jars.
918
#search_paths=/app1/lib;/app2/lib
922
#search_paths=/app1/lib;/app2/lib
919
923
920
# Users can define additional classpath items by setting the property below
924
# List of paths that JMeter will search for utility and plugin dependency classes.
921
# - for example, utility jars or JUnit test cases
925
# Use your platform path separator to separate multiple paths.
922
#
926
# A path item can either be a jar file or a directory.
923
# Use the default separator for the host version of Java
927
# Any jar file in such a directory will be automatically included,
928
# jar files in sub directories are ignored.
929
# The given value is in addition to any jars found in the lib directory.
930
# All entries will be added to the class path of the system class loader
931
# and also to the path of the JMeter internal loader.
924
# Paths with spaces may cause problems for the JVM
932
# Paths with spaces may cause problems for the JVM
925
#user.classpath=../classes;../jars/jar1.jar
933
#user.classpath=../classes;../lib;../app1/jar1.jar;../app2/jar2.jar
926
934
935
# List of paths (separated by ;) that JMeter will search for utility
936
# and plugin dependency classes.
937
# A path item can either be a jar file or a directory.
938
# Any jar file in such a directory will be automatically included,
939
# jar files in sub directories are ignored.
940
# The given value is in addition to any jars found in the lib directory
941
# or given by the user.classpath property.
942
# All entries will be added to the path of the JMeter internal loader only.
943
# For plugin dependencies using plugin_dependency_paths should be preferred over
944
# user.classpath.
945
#plugin_dependency_paths=../dependencies/lib;../app1/jar1.jar;../app2/jar2.jar
946
927
# Classpath finder
947
# Classpath finder
928
# ================
948
# ================
929
# The classpath finder currently needs to load every single JMeter class to find
949
# The classpath finder currently needs to load every single JMeter class to find
Lines 952-955 Link Here
952
972
953
# Comma separated list of files that contain reference to templates and their description
973
# Comma separated list of files that contain reference to templates and their description
954
# Path must be relative to jmeter root folder
974
# Path must be relative to jmeter root folder
955
#template.files=/bin/templates/templates.xml
975
#template.files=/bin/templates/templates.xml
(-)bin/user.properties (-8 / +28 lines)
Lines 19-36 Link Here
19
# Classpath configuration
19
# Classpath configuration
20
#---------------------------------------------------------------------------
20
#---------------------------------------------------------------------------
21
#
21
#
22
# List of paths (separated by ;) to search for additional JMeter extension classes
22
# List of paths (separated by ;) to search for additional JMeter plugin classes,
23
# - for example new GUI elements and samplers
23
# for example new GUI elements and samplers.
24
# These are in addition to lib/ext. Do not use this for utility jars.
24
# A path item can either be a jar file or a directory.
25
# Any jar file in such a directory will be automatically included,
26
# jar files in sub directories are ignored.
27
# The given value is in addition to any jars found in the lib/ext directory.
28
# Do not use this for utility ir plugin dependecy jars.
25
#search_paths=/app1/lib;/app2/lib
29
#search_paths=/app1/lib;/app2/lib
26
30
27
# Users can define additional classpath items by setting the property below
31
# List of paths that JMeter will search for utility and plugin dependency classes.
28
# - for example, utility jars or JUnit test cases
32
# Use your platform path separator to separate multiple paths.
29
#
33
# A path item can either be a jar file or a directory.
30
# Use the default separator for the host version of Java
34
# Any jar file in such a directory will be automatically included,
35
# jar files in sub directories are ignored.
36
# The given value is in addition to any jars found in the lib directory.
37
# All entries will be added to the class path of the system class loader
38
# and also to the path of the JMeter internal loader.
31
# Paths with spaces may cause problems for the JVM
39
# Paths with spaces may cause problems for the JVM
32
#user.classpath=../classes;../jars/jar1.jar
40
#user.classpath=../classes;../lib;../app1/jar1.jar;../app2/jar2.jar
33
41
42
# List of paths (separated by ;) that JMeter will search for utility
43
# and plugin dependency classes.
44
# A path item can either be a jar file or a directory.
45
# Any jar file in such a directory will be automatically included,
46
# jar files in sub directories are ignored.
47
# The given value is in addition to any jars found in the lib directory
48
# or given by the user.classpath property.
49
# All entries will be added to the path of the JMeter internal loader only.
50
# For plugin dependencies using plugin_dependency_paths should be preferred over
51
# user.classpath.
52
#plugin_dependency_paths=../dependencies/lib;../app1/jar1.jar;../app2/jar2.jar
53
34
#---------------------------------------------------------------------------
54
#---------------------------------------------------------------------------
35
# Logging configuration
55
# Logging configuration
36
#---------------------------------------------------------------------------
56
#---------------------------------------------------------------------------
(-)xdocs/changes.xml (+9 lines)
Lines 107-112 Link Here
107
107
108
<h4>* ModuleController has been improved to better handle changes to referenced controllers</h4>
108
<h4>* ModuleController has been improved to better handle changes to referenced controllers</h4>
109
109
110
<h4>* Improved class loader configuration, see <bugzilla>55503</bugzilla></h4>
111
<p>
112
<ul>
113
<li>New property "plugin_dependency_paths" for plugin dependencies</li>
114
<li>Properties "search_paths", "user.classpath" and "plugin_dependency_paths"
115
    now automatically add all jars from configured directories</li>
116
</ul>
117
</p>
118
110
<h4>* Best-practices section has been improved, ensure you read it to get the most out of JMeter</h4>
119
<h4>* Best-practices section has been improved, ensure you read it to get the most out of JMeter</h4>
111
120
112
<h3><u>GUI and ergonomy Improvements:</u></h3>
121
<h3><u>GUI and ergonomy Improvements:</u></h3>
(-)xdocs/usermanual/component_reference.xml (-3 / +7 lines)
Lines 5569-5581 Link Here
5569
</p>
5569
</p>
5570
<p>
5570
<p>
5571
Test plan now provides an easy way to add classpath setting to a specific test plan. 
5571
Test plan now provides an easy way to add classpath setting to a specific test plan. 
5572
The feature is additive, meaning that you can add jar files or directories, but removing an entry requires restarting JMeter.
5572
The feature is additive, meaning that you can add jar files or directories,
5573
but removing an entry requires restarting JMeter.
5573
Note that this cannot be used to add JMeter GUI plugins, because they are processed earlier.
5574
Note that this cannot be used to add JMeter GUI plugins, because they are processed earlier.
5574
However it can be useful for utility jars such as JDBC drivers. 
5575
However it can be useful for utility jars such as JDBC drivers. The jars are only added to
5576
the search path for the JMeter loader, not for the system class loader.
5575
</p>
5577
</p>
5576
<p>
5578
<p>
5577
JMeter properties also provides an entry for loading additional classpaths.
5579
JMeter properties also provides an entry for loading additional classpaths.
5578
In jmeter.properties, edit "user.classpath" to include additional libraries.
5580
In jmeter.properties, edit "user.classpath" or "plugin_dependency_paths" to include additional libraries.
5581
See <a href="get-started.html#classpath">JMeter's Classpath</a> and
5582
<a href="get-started.html#configuring_jmeter">Configuring JMeter</a> for details.
5579
</p>
5583
</p>
5580
</description>
5584
</description>
5581
</component>
5585
</component>
(-)xdocs/usermanual/get-started.xml (-11 / +36 lines)
Lines 257-277 Link Here
257
<p>JMeter automatically finds classes from jars in the following directories:</p>
257
<p>JMeter automatically finds classes from jars in the following directories:</p>
258
<ul>
258
<ul>
259
<li>JMETER_HOME/lib - used for utility jars</li>
259
<li>JMETER_HOME/lib - used for utility jars</li>
260
<li>JMETER_HOME/lib/ext - used for JMeter components and add-ons</li>
260
<li>JMETER_HOME/lib/ext - used for JMeter components and plugins</li>
261
</ul>
261
</ul>
262
<p>If you have developed new JMeter components,
262
<p>If you have developed new JMeter components,
263
then you should jar them and copy the jar into JMeter's <b>lib/ext</b> directory.
263
then you should jar them and copy the jar into JMeter's <b>lib/ext</b> directory.
264
JMeter will automatically find JMeter components in any jars found here.
264
JMeter will automatically find JMeter components in any jars found here.
265
Do not use lib/ext for utility jars or dependency jars used by the plugins;
266
it is only intended for JMeter components and plugins.
265
</p>
267
</p>
266
<p>Support jars (libraries etc) should be placed in the <b>lib</b> directory.</p>
268
<p>If you don't want to put JMeter plugin jars in the <b>lib/ext</b> directory,
267
268
<p>If you don't want to put JMeter extension jars in the <b>lib/ext</b> directory,
269
then define the property <b>search_paths</b> in jmeter.properties.
269
then define the property <b>search_paths</b> in jmeter.properties.
270
Do not use lib/ext for utility jars; it is only intended for JMeter components.
271
</p>
270
</p>
271
<p>Utility and dependency jars (libraries etc) can be placed in the <b>lib</b> directory.</p>
272
<p>If you don't want to put such jars in the <b>lib</b> directory,
273
then define the property <b>user.classpath</b> or <b>plugin_dependency_paths</b>
274
in jmeter.properties. See below for an explanation of the differences.
275
</p>
272
<p>
276
<p>
273
Other jars (such as JDBC, JMS implementations and any other support libaries needed by the JMeter code)
277
Other jars (such as JDBC, JMS implementations and any other support libaries needed by the JMeter code)
274
 should be placed in the <b>lib</b> directory - not the <b>lib/ext</b> directory</p>
278
should be placed in the <b>lib</b> directory - not the <b>lib/ext</b> directory,
279
or added to <b>user.classpath</b>.</p>
275
<p>Note: JMeter will only find .jar files, not .zip.</p>
280
<p>Note: JMeter will only find .jar files, not .zip.</p>
276
<p>You can also install utility Jar files in $JAVA_HOME/jre/lib/ext, or you can set the property <b>user.classpath</b> in jmeter.properties</p>
281
<p>You can also install utility Jar files in $JAVA_HOME/jre/lib/ext, or you can set the property <b>user.classpath</b> in jmeter.properties</p>
277
<p>Note that setting the CLASSPATH environment variable will have no effect.
282
<p>Note that setting the CLASSPATH environment variable will have no effect.
Lines 543-556 Link Here
543
  You may list their classname or their class label (the string that appears
548
  You may list their classname or their class label (the string that appears
544
  in JMeter's UI) here, and they will no longer appear in the menus.</property>
549
  in JMeter's UI) here, and they will no longer appear in the menus.</property>
545
  <property name="search_paths">
550
  <property name="search_paths">
546
  List of paths (separated by ;) that JMeter will search for JMeter add-on classes;
551
  List of paths (separated by ;) that JMeter will search for JMeter plugin classes,
547
  for example additional samplers.
552
  for example additional samplers. A path item can either be a jar file or a directory.
548
  This is in addition to any jars found in the lib/ext directory.
553
  Any jar file in such a directory will be automatically included in search_paths,
554
  jar files in sub directories are ignored.
555
  The given value is in addition to any jars found in the lib/ext directory.
549
  </property>
556
  </property>
550
  <property name="user.classpath">
557
  <property name="user.classpath">
551
  List of paths that JMeter will search for utility classes.
558
  List of paths that JMeter will search for utility and plugin dependency classes.
552
  This is in addition to any jars found in the lib directory.
559
  Use your platform path separator to separate multiple paths.
560
  A path item can either be a jar file or a directory.
561
  Any jar file in such a directory will be automatically included in user.classpath,
562
  jar files in sub directories are ignored.
563
  The given value is in addition to any jars found in the lib directory.
564
  All entries will be added to the class path of the system class loader
565
  and also to the path of the JMeter internal loader.
553
  </property>
566
  </property>
567
  <property name="plugin_dependency_paths">
568
  List of paths (separated by ;) that JMeter will search for utility
569
  and plugin dependency classes.
570
  A path item can either be a jar file or a directory.
571
  Any jar file in such a directory will be automatically included in plugin_dependency_paths,
572
  jar files in sub directories are ignored.
573
  The given value is in addition to any jars found in the lib directory
574
  or given by the user.classpath property.
575
  All entries will be added to the path of the JMeter internal loader only.
576
  For plugin dependencies using plugin_dependency_paths should be preferred over
577
  user.classpath.
578
  </property>
554
  <property name="user.properties">
579
  <property name="user.properties">
555
  Name of file containing additional JMeter properties. 
580
  Name of file containing additional JMeter properties. 
556
  These are added after the initial property file, but before the -q and -J options are processed.
581
  These are added after the initial property file, but before the -q and -J options are processed.

Return to bug 55503