java反编译 源码_java根据jar反编译指定类的源码

作者

时间

雨中星辰

2019-05-06

背景

由于领导通知需要让用户上传接口jar包,根据用户指定的接口,从jar包中反编译出源码。

一看到这个需求,第一个想到的就是大名鼎鼎的jd-gui啊。用了这么多年,一直都很好用。

开始在网上各种找,无果。

在maven仓库搜了一下,无果。

又去githup搜了一下,有了。githup地址为:https://github.com/java-decompiler/jd-gui

但是没有讲怎么用啊,囧。。。

算了,下载一下源码研究一下吧。发现用起来还是很简单的。

/**

*

* @param jarPath 要反编译的jar包的绝对路径

* @param outPath 反编译的源码输出的目录

* @return

* @throws DecompilerException

* @throws IOException

*/

public int decompile(String jarPath, String outPath) throws DecompilerException, IOException

/**

*

* @param jarPath 要反编译的jar包的绝对路径

* @param internalClassName 要反编译的class文件的路径:例:dcloud/common/Auth.java

* @return

* @throws DecompilerException

*/

public String decompileClass(String jarPath, String internalClassName) throws DecompilerException

例:

Decompiler decompiler = new Decompiler();

Map decompile = decompiler.decompile("D:\\java_team\\repository\\com\\sgcc\\epri\\dcloud\\dcloud.common.Auth\\2.0.0\\dcloud.common.Auth-2.0.0.jar");

String source = decompile.get("dcloud/common/Auth.java");

System.out.println(source);

需要注意的是:gd-gui项目在maven仓库中没有,需要将项目中githup中下载下来,进行打包。

git clone https://github.com/java-decompiler/jd-gui.git

cd jd-gui

./gradlew build

打包后的文件在jd-gui/build/libs中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值