您的位置:首页 > 编程语言 > Java开发

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

2016-04-05 21:53 417 查看
在学习编程的过程当中,我们需要经常看一些源码。一般情况下,我们都需要导入源码,才能打开项目中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>

<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文件了,希望对大家有所帮助!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: