diff --git a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index 868b6b60d5..9545f212ba 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -14,6 +14,7 @@ import org.apache.jorphan.collections.HashTree; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.io.File; import java.io.InputStream; import java.lang.reflect.Field; @@ -24,14 +25,15 @@ public class JMeterService { private JmeterProperties jmeterProperties; public void run(String testId, String debugReportId, InputStream is) { - String JMETER_HOME = jmeterProperties.getHome(); + String JMETER_HOME = getJmeterHome(); + String JMETER_PROPERTIES = JMETER_HOME + "/bin/jmeter.properties"; JMeterUtils.loadJMeterProperties(JMETER_PROPERTIES); JMeterUtils.setJMeterHome(JMETER_HOME); try { Object scriptWrapper = SaveService.loadElement(is); HashTree testPlan = getHashTree(scriptWrapper); - addBackendListener(testId, debugReportId, testPlan); + addBackendListener(testId, debugReportId, testPlan); LocalRunner runner = new LocalRunner(testPlan); runner.run(); @@ -41,6 +43,20 @@ public class JMeterService { } } + private String getJmeterHome() { + String home = getClass().getResource("/").getPath() + "/jmeter"; + try { + File file = new File(home); + if (file.exists()) { + return home; + } else { + return jmeterProperties.getHome(); + } + } catch (Exception e) { + return jmeterProperties.getHome(); + } + } + private HashTree getHashTree(Object scriptWrapper) throws Exception { Field field = scriptWrapper.getClass().getDeclaredField("testPlan"); field.setAccessible(true);