1. 程式人生 > >編譯jmeter5.0原始碼

編譯jmeter5.0原始碼

 

 

jmeter5.0使用過程中,遇到request或者response亂碼的情況,想要一次性解決這個問題,需要編譯ApacheJMeter_http.jar這個包(lib\ext檔案下)裡的RequestViewHTTP.class檔案把encoding預設值修改成UTF-8

由於不懂java本想網上下載編譯好的ApacheJMeter_http.jar,有同學應用可以 但是我這邊還是不可以,還有http錄製的時候錄製到的中文也是亂碼 所以還得編譯DefaultSamplerCreator.class檔案但是網上下載的ApacheJMeter_http.jar只編譯了的RequestViewHTTP.class,所以決定自己編譯jmeter5.0原始碼

1、jmeter5.0原始碼下載地址:http://jmeter.apache.org/download_jmeter.cgi,windows系統選擇Source目錄下的zip包;解壓到任何資料夾

2、eclipse IDE下載地址:https://www.eclipse.org/downloads/,預設安裝就可以

3、開啟eclipse 選擇file-new-java project(jmeter是java寫的),配置如圖,點選next

2、選擇建立的專案myjmeter右鍵選擇import。。。按下面的步驟匯入jmeter5.0的原始碼

Browse...選擇解壓後的jmeter5.0

3、build.xml用ant editor開啟(build.xml右鍵選擇open with-ant editor)

4、用ant執行download_jars,在build.xml列表裡找到download_jars雙擊執行,下載依賴的jar包,或者選中download_jars,點選執行按鈕

 

5、開啟navigator( Windows-Show View-Navigator)雙擊開啟.classpath 和 eclipse.classpath,複製eclipse.classpath內容到.classpath

  同樣的步驟複製eclipse.project內容到.project,重啟eclipse(重啟後如果myjmeter專案和下載的包提示紅色X,先不用管,因為還沒有匯入他們依賴的包)

 

 

 

6、myjmeter右鍵-Build Path-Configure Build Path...去除帶紅色X號的jar包(remove),新增myjmeter-lib和其子資料夾下的所有jar包

 

 

7、新增完成以後,開啟RequestViewHttp.java和PostWrite.java修改預設編碼為uft-8,

 

8、 DefaultSamplerCreator.java 中encoding呼叫的PostWrite.java的編碼可以不用修改也可以直接修改成"utf-8"

 

 

9、複製jmeter5.0原始碼中的 jmeter.properties和log4j2.xml到myjmeter專案bin目錄下,

10、修改完後,ant editor列表中執行install,執行完成後myjmeter專案和jar包不在現實紅色X提示

11、雙擊myjmeter資料夾bin目錄下的ApacheJMeter.jar,jmeter執行成功

12、jd-gui開啟myjmeter-lib-ext-ApacheJMeter_http.jar檢查之前修改的有沒有生效

到此編譯成功,大家可以拿編譯好的ApacheJMeter_http.jar包替換jmeter安裝版本里的這個包就可以了