原網址:http://blog.csdn.net/qq_29829081/article/details/51068570
在學習編程的過程當中,我們需要經常看一些源碼。一般情況下,我們都需要導入源碼,才能打開項目中jar包裏面的class文件,但是這樣操作非常麻煩,如果不用關聯源碼就可以查看源碼,會大大提高學習效率。因此,我們就需要在開發工具中配置反編譯工具。我在網上搜了很多資料,結果都配置失敗,最後有一篇博客(http://blog.csdn.net/yjhandyw/article/details/21083071#comments)給了啓發,最後在MyEclipse10當中配置成功。現在就將自己的一點經驗分享給大家,希望對大家有所幫助。
例如:一個web項目當中我們導入了很多jar包,裏面的class文件都不能讀取源碼!點擊之後如下圖所示:
MyEclipse10當中配置Jad反編譯工具的步驟:
1、下載jad.exe和net.sf.jadclipse_3.3.0.jar文件。
2、將下載的jad反編譯相關文件.rar文件解壓,並將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)。
4、創建一個java項目,將下面的代碼複製(引用自http://blog.csdn.net/yjhandyw/article/details/21083071#comments)進去直接運行。
注意:將這裏的路徑替換成自己插件的安裝目錄,例如我的是"D:\\develop\\MyEclipse 10\\dropins\\plugins"。
運行CreatePluginsConfig.javaimport 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); } }
運行結果:
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文件了,希望對大家有所幫助!