如何在MyEclipse10中配置Jad反编译工具?

来源:互联网 发布:postscript软件下载 编辑:程序博客网 时间:2024/05/01 02:13

        在学习编程的过程当中,我们需要经常看一些源码。一般情况下,我们都需要导入源码,才能打开项目中jar包里面的class文件,但是这样操作非常麻烦,如果不用关联源码就可以查看源码,会大大提高学习效率。因此,我们就需要在开发工具中配置反编译工具。我在网上搜了很多资料,结果都配置失败,最后有一篇博客(http://blog.csdn.NET/yjhandyw/article/details/21083071#comments)给了启发,最后在MyEclipse10当中配置成功。现在就将自己的一点经验分享给大家,希望对大家有所帮助。

例如:一个web项目当中我们导入了很多jar包,里面的class文件都不能读取源码!点击之后如下图所示:


MyEclipse10当中配置Jad反编译工具的步骤:

1、下载jad158g.win.zip文件和net.sf.jadclipse_3.3.0.jar文件。


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>
[java] view plain copy
print?
  1. <span style="font-size:12px;">import java.io.File;     
  2. import java.util.ArrayList;     
  3. import java.util.List;     
  4.   
  5. /**   
  6. * MyEclipse10.0 插件配置代码生成器    
  7. */    
  8.   
  9. public class CreatePluginsConfig     
  10. {     
  11.     
  12.     public CreatePluginsConfig()     
  13.     {     
  14.     }     
  15.     
  16.     public void print(String path)     
  17.     {     
  18.         List<String> list = getFileList(path);     
  19.         if (list == null)     
  20.         {     
  21.             return;     
  22.         }     
  23.     
  24.         int length = list.size();     
  25.         for (int i = 0; i < length; i++)     
  26.         {     
  27.             String result = "";     
  28.             String thePath = getFormatPath(getString(list.get(i)));     
  29.             File file = new File(thePath);     
  30.             if (file.isDirectory())     
  31.             {     
  32.                 String fileName = file.getName();     
  33.                 if (fileName.indexOf("_") < 0)     
  34.                 {     
  35.                     print(thePath);     
  36.                     continue;     
  37.                 }     
  38.                 String[] filenames = fileName.split("_");     
  39.                 String filename1 = filenames[0];     
  40.                 String filename2 = filenames[1];     
  41.                 result = filename1 + "," + filename2 + ",file:/" + path + "\\"    
  42.                         + fileName + "\\,4,false";     
  43.                 System.out.println(result);     
  44.             } else if (file.isFile())     
  45.             {     
  46.                 String fileName = file.getName();     
  47.                 if (fileName.indexOf("_") < 0)     
  48.                 {     
  49.                     continue;     
  50.                 }     
  51.                 int last = fileName.lastIndexOf("_");   
  52.                 String filename1 = fileName.substring(0, last);     
  53.                 String filename2 = fileName.substring(last + 1, fileName     
  54.                         .length() - 4);     
  55.                 result = filename1 + "," + filename2 + ",file:/" + path + "\\"    
  56.                         + fileName + ",4,false";     
  57.                 System.out.println(result);     
  58.             }     
  59.     
  60.         }     
  61.     }     
  62.     
  63.     public List<String> getFileList(String path)     
  64.     {     
  65.         path = getFormatPath(path);     
  66.         path = path + "/";     
  67.         File filePath = new File(path);     
  68.         if (!filePath.isDirectory())     
  69.         {     
  70.             return null;     
  71.         }     
  72.         String[] filelist = filePath.list();     
  73.         List<String> filelistFilter = new ArrayList<String>();     
  74.     
  75.         for (int i = 0; i < filelist.length; i++)     
  76.         {     
  77.             String tempfilename = getFormatPath(path + filelist[i]);     
  78.             filelistFilter.add(tempfilename);     
  79.         }     
  80.         return filelistFilter;     
  81.     }     
  82.     
  83.     public String getString(Object object)     
  84.     {     
  85.         if (object == null)     
  86.         {     
  87.             return "";     
  88.         }     
  89.         return String.valueOf(object);     
  90.     }     
  91.     
  92.     public String getFormatPath(String path)     
  93.     {     
  94.         path = path.replaceAll("\\\\", "/");     
  95.         path = path.replaceAll("//""/");     
  96.         return path;     
  97.     }     
  98.     
  99.     public static void main(String[] args)     
  100.     {     
  101.         //将这里的路径替换成自己插件的安装目录,例如我的是"D:\\develop\\MyEclipse 10\\dropins\\plugins"  
  102.         String plugin = "D:\\develop\\MyEclipse 10\\dropins\\plugins";  
  103.         new CreatePluginsConfig().print(plugin);     
  104.     }     
  105. }  </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文件了,希望对大家有所帮助!

0 0
原创粉丝点击