title: How can we write java code in JMETER?
body: <p>How can we write java code in JMETER?</p>
  
  <p>I got some information from google,Java Sampler is using for that and I tried that way
  Just i did copy paste some codes from googe,but getting errors from import also ,Always org.apache.jmeter is showing error,Any body can tell me about implementation and sample code alao</p>
  
  <p>This is my java code</p>
  
  <pre><code>package com.code4reference.jmeter.functions;
  import org.apache.jmeter.engine.util.CompoundVariable; 
  import org.apache.jmeter.functions.AbstractFunction; 
  
  public class JavaRequestSamplerDemo extends AbstractJavaSamplerClient {
  
    @Override
    public SampleResult runTest(JavaSamplerContext ctx) {
      JMeterVariables vars = JMeterContextService.getContext().getVariables();
      vars.put("demo", "demoVariableContent");
  
      SampleResult sampleResult = new SampleResult();
      sampleResult.setSuccessful(true);
      sampleResult.setResponseCodeOK();
      sampleResult.setResponseMessageOK();
      return sampleResult;
    }  
  }
  </code></pre>