Building JMeter plug-in with Eclipse
\[http://www.eclipse.org Eclipse\] is a very popular Java development environment. Wiki Markup
Targetted to Eclipse 3.1 and JMeter 2.1 trunk version. JMeter isn't designed to be edited and build from Eclipse IDE (JMeter uses Ant build file and complex path/jar structure with optional dependencies), so some work has to be done before we get wheels running.
NOTE: the JMeter trunk code This page is very out of date - the current branch is rel-2-2. Also, there is an eclipse.classpath which can be used to set up the appropriate exclusions etc - sebb
Building JMeter from sources with Eclipse
...
- Check out JMeter trunk from Subversion
- Get Subclipse plug-in for Eclipse http://subclipse.tigris.org/
- Check out http://svn.apache.org/repos/asf/jakarta/jmeter/rel-2-2 as jmeter-trunk Java project
- Trunk might not be the latest version. Ask from JMeter mailing list which is the active development branch of JMeter.
...
- Let Eclipse internal compiler handle the building of JMeter, instead of relying on JMeter's own Ant build files. When Eclipse handles building, development work goes more smoothly.
- Source build paths: test/src
- src/protocol/ftp
- Add all paths which contain /org folder
- src/
- monitor and src/protocol
- contain nested levels so be careful choosing the right target folders
- src/protocol/
- src/protocol/tcp
- src/monitor/components
- src/monitor/model
- src/components
- src/core
- src/examples
- src/functions
- src/htmlparser
- src/jorphan
- src/junit
- jndi has a strange directory structure so skip this path
- Exclude following files from building They (they have missing dependencies)
- and are related to HTTP security which you are not probably interested in
- org/apache/jmeter/util/JsseSSLManager.java (HTTP security)
- org/apache/jmeter/util/keystore/DefaultKeyStore.java (HTTP security)
- org/apache/jmeter/util/keystore/PKCS12KeyStore.java (HTTP security)
- org/apache/jmeter/protocol/http/sampler/WebServiceSampler (depend on javax.mail)
- org/apache/jmeter/protocol/http/control/gui/WebServiceSamplerGui (depend on javax.mail)
- org/apache/jmeter/reporters/ (depend on javax.mail)
- ...or just copy missing JARs from Internet (Java MAIL API: mailapi.jar, etc.), it's easier
- ...or just add mailapi.jar from Internet to build path and remove src/protocol/jms and src/htmlparser16 from source folders
- Add libraries
- All jar files under lib/ folder
- Export libraries
- At least logkit libraries are needed in projects depended on JMeter
- Export them at order and export tab page in the project properties dialog
- To make log4j logging to Eclipse console work, you need to comment out change some code. Read more notes about this below. Class is You can find the affected code in the org.apacha.jmeter.jorphan.logging.LoggingManager.initializeLogging(Properties) method. Read more notes about this below.
No Format |
---|
public static void initializeLogging(Properties properties) { if (logManager == null) { logManager = new LoggingManager(); } /* This following code caused me to lost 3 hours of working time * and now I am extra frustrated setFormat(properties); } setFormat(properties); setPriority(properties.getProperty(LOG_PRIORITY, "INFO")); // Direct to system out isWriterSystemOut = true; isTargetSystemOut = true; WriterTarget wt = new WriterTarget(new OutputStreamWriter(System.out), getFormat()); Hierarchy.getDefaultHierarchy().setDefaultLogTarget(wt); setLoggingLevels(properties); // if (logManager == null) { // logManager = new LoggingManager(); // } // // setFormat(properties); // // // Set the top-level defaults // setTarget(makeWriter(properties.getProperty(LOG_FILE, "jmeter.log"), LOG_FILE)); // setPriority(properties.getProperty(LOG_PRIORITY, "INFO")); // // setLoggingLevels(properties); // // now set the individual categories (if any) * */ // // setConfig(properties);// Further configuration } |
- Now Eclipse should build JMeter without errors (stop icons in source tree)
...
- Set up your custom plug-in project
- Create a new Java project
- Add jmeter-trunk to project dependencies
- Create bin/ and src/ folders
- Create the src/jmeter.properties in the bin/ file
- This defines where JMeter internal class loader looks for classes
- It should look like this (please note that you have to adapt the first part of the search_paths property so it points to your JMeter Eclipse project!)
No Format |
---|
# JMeter uses case sensitive string matching to test these paths against absolute class path. # This is very bad since paths must be *exactly* here as they appear in Java classpath. # Hopefully this will be fixed in the future versions. Note Windows needs to escape \ character as \\. search_paths=C:\\icecom\\jmeter-2.2\\bin;. # Add JMeter output folder and our plug-in output folder to paths from which # plug-ins are searched search_paths=C:\\xxx\\jmeter-trunk\\bin;. File that holds a record of name changes for backward compatibility issues upgrade_properties=upgrade.properties # Should JMeter automatically load additional JMeter properties? # File name to look for (comment to disable) user.properties=user.properties # Should JMeter automatically load additional system properties? # File name to look for (comment to disable) system.properties=system.properties log_level.jorphan=WARN log_level.jmeter.testbeans=WARN log_level.jmeter.gui=WARN log_level.jmeter.engine.util=WARN log_level.jmeter.threads.util=WARN log_level.fi.xxx=TRACE # Widen default log output for Eclipse console log_format=%-6.6{priority} (%-10.10{thread}) [%-25.25{category}] %{message} . |
- Create the src/log4j.conf in src/ file
No Format |
---|
log4j.rootLogger=debug, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout # Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n |
...
- Set working directory to bin/ in your project
- JMeter is hard coded to look up jmeter.properties in the launch folder
- E.g. ${workspace_loc:SIPPerformanceStresser/bin}
- Copy lib/ from jmeter-trunk to your plug-in project root
- JMeter is hard coded to look up jars from ../lib
- Main class: org.apache.jmeter.NewDriver
Creating components
JMeter 2.x uses its internal [TestBean]-framework for adding new components. For more information, see \[:DeveloperManual/TestBeanTutorial:Tutorial - Making a JMeter TestBean\], \[http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/extending/jmeter_tutorial.pdf?view=log&pathrev=325123 this PDF\] and JMeter source code Wiki Markup
For each component you need
Wiki Markup An element class which interits from \[TestElement, ConfigurationElement, XXXElement\] and implements [TestBean] interface. [TestBean] interface marks classes which JMeter plug-in class loader loads automatically. \\
2. Each TestBean class needs BeanInfoSupport class whichs describes the properties of the element class. This class name must be MyTestElement + BeanInfo, e.g. MyTestElementBeanInfo, or the class loader doesn't find it.
...
Java source fi/xxx/jmeter/sip/core/SIPReceiverBeanInfoSupportSIPReceiverBeanInfo
No Format |
---|
package fi.xxx.jmeter.sip.core; import java.beans.PropertyDescriptor; import org.apache.jmeter.config.CSVDataSet; import org.apache.jmeter.testbeans.BeanInfoSupport; public class SIPReceiverBeanInfo extends BeanInfoSupport { public SIPReceiverBeanInfo() { super(SIPReceiver.class); createPropertyGroup("sip_receiver", new String[] { "filename", "variableNames", "delimiter" }); PropertyDescriptor p = property("filename"); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, ""); p.setValue(NOT_EXPRESSION, Boolean.TRUE); p = property("variableNames"); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, ""); p.setValue(NOT_EXPRESSION, Boolean.TRUE); p = property("delimiter"); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, ","); p.setValue(NOT_EXPRESSION, Boolean.TRUE); } } |
Properties file fi/xxx/jmeter/sip/core/SIPreceiverSIPreceiverResources.properties
No Format |
---|
displayName=SIP Receiver sip_receiver.displayName=Configure SIP receiver filename.displayName=Filename filename.shortDescription=Name of the file (within your supporting file directory) that holds cvs data variableNames.displayName=Variable Names (comma-delimited) variableNames.shortDescription=List your variable names in order to match the order of columns in your csv data. Separate by commas. delimiter.displayName=Delimiter (use '\\t' for tab) delimiter.shortDescription=Enter the delimiter ('\\t' for tab) |
...
If widget labels are not read from resouces file, your the properties file of your component has a wrong filename