如何在MyEclipse10中配置Jad反編譯工具?
在學習程式設計的過程當中,我們需要經常看一些原始碼。一般情況下,我們都需要匯入原始碼,才能開啟專案中jar包裡面的class檔案,但是這樣操作非常麻煩,如果不用關聯原始碼就可以檢視原始碼,會大大提高學習效率。因此,我們就需要在開發工具中配置反編譯工具。我在網上搜了很多資料,結果都配置失敗,最後有一篇部落格(http://blog.csdn.net/yjhandyw/article/details/21083071#comments)給了啟發,最後在MyEclipse10當中配置成功。現在就將自己的一點經驗分享給大家,希望對大家有所幫助。
例如:一個web專案當中我們匯入了很多jar包,裡面的class檔案都不能讀取原始碼!點選之後如下圖所示:
MyEclipse10當中配置Jad反編譯工具的步驟:
2、將下載的jad158g.win.zip檔案解壓,並將jad.exe檔案複製到jdk的安裝目錄下的jre資料夾下。例如:D:\develop\Java\jre7\bin\jad.exe。
3、將下載的net.sf.jadclipse.3.3.0.jar,複製到MyEclipse的安裝目錄下。
- 在安裝目錄裡面新建dropins資料夾,如果有dropins資料夾則不需要新建。
- 在dropins資料夾下面新建features資料夾和plugins資料夾。
- 將net.sf.jadclipse.3.3.0.jar分別複製到features資料夾和plugins資料夾(不復制到這個資料夾,不會生成JadClipse)。
例如:最後複製在這兩個路徑下。
D:\develop\MyEclipse 10\dropins\plugins\net.sf.jadclipse.3.3.0.jar
D:\develop\MyEclipse 10\dropins\features\net.sf.jadclipse.3.3.0.jar
4、建立一個java專案,將下面的程式碼複製(引用自http://blog.csdn.net/yjhandyw/article/details/21083071#comments)進去直接執行。
注意:將這裡的路徑替換成自己外掛的安裝目錄,例如我的是"D:\\develop\\MyEclipse 10\\dropins\\plugins"。
<span style="font-size:12px;">CreatePluginsConfig.java</span>
<span style="font-size:12px;">import java.io.File; import java.util.ArrayList; import java.util.List; /** * MyEclipse10.0 外掛配置程式碼生成器 */ public class CreatePluginsConfig { public CreatePluginsConfig() { } public void print(String path) { List<String> list = getFileList(path); if (list == null) { return; } int length = list.size(); for (int i = 0; i < length; i++) { String result = ""; String thePath = getFormatPath(getString(list.get(i))); File file = new File(thePath); if (file.isDirectory()) { String fileName = file.getName(); if (fileName.indexOf("_") < 0) { print(thePath); continue; } String[] filenames = fileName.split("_"); String filename1 = filenames[0]; String filename2 = filenames[1]; result = filename1 + "," + filename2 + ",file:/" + path + "\\" + fileName + "\\,4,false"; System.out.println(result); } else if (file.isFile()) { String fileName = file.getName(); if (fileName.indexOf("_") < 0) { continue; } int last = fileName.lastIndexOf("_"); String filename1 = fileName.substring(0, last); String filename2 = fileName.substring(last + 1, fileName .length() - 4); result = filename1 + "," + filename2 + ",file:/" + path + "\\" + fileName + ",4,false"; System.out.println(result); } } } public List<String> getFileList(String path) { path = getFormatPath(path); path = path + "/"; File filePath = new File(path); if (!filePath.isDirectory()) { return null; } String[] filelist = filePath.list(); List<String> filelistFilter = new ArrayList<String>(); for (int i = 0; i < filelist.length; i++) { String tempfilename = getFormatPath(path + filelist[i]); filelistFilter.add(tempfilename); } return filelistFilter; } public String getString(Object object) { if (object == null) { return ""; } return String.valueOf(object); } public String getFormatPath(String path) { path = path.replaceAll("\\\\", "/"); path = path.replaceAll("//", "/"); return path; } public static void main(String[] args) { //將這裡的路徑替換成自己外掛的安裝目錄,例如我的是"D:\\develop\\MyEclipse 10\\dropins\\plugins" String plugin = "D:\\develop\\MyEclipse 10\\dropins\\plugins"; new CreatePluginsConfig().print(plugin); } } </span>
執行結果:
net.sf.jadclipse,3.3.0,file:/D:\develop\MyEclipse 10\dropins\plugins\net.sf.jadclipse_3.3.0.jar,4,false
5、找到MyEclipse10安裝目錄下的org.eclipse.equinox.simpleconfigurators資料夾下面的bundles.info檔案,用記事本開啟,將上面程式的執行結果加入到檔案最後,並儲存。
例如:D:\develop\MyEclipse 10\configuration\org.eclipse.equinox.simpleconfigurator\bundles.info
6、重啟MyEclipse10,進行配置JadClipse。
在MyEclipse10中,開啟Windows---> Perferences--->General--->Editors--->File Association,選擇*.class(如果沒有的話就自己點選Add新增一個),在下面的Associated editors中將JadClipse Class File Viewer設定為預設(default)。如下圖所示:
7、在MyEclipse中設定JadClipse的Path to decompiler和Directory for temporary files。
- 在MyEclipse10中,開啟Windows---> Perferences--->Java--->JadClipse,按照下圖填寫路徑名稱,格式最好一致,同時選中Use Eclipse code formatter (overrides Jad formatting instructions)。
- 在MyEclipse10中,開啟Windows---> Perferences--->Java--->JadClipse--->Misc,選中Convert Unicode strings into ANSI strings,這個選項主要是防止亂碼的。
配置完以上這些,就可以點開class檔案了,希望對大家有所幫助!