Eclipse:如何反编译 jar 并将其作为项目加载?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3452673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 19:34:05  来源:igfitidea点击:

Eclipse: How Do I decompile jar and load it as a project?

eclipsejar

提问by KJW

how can I decompile a jar and load it as a project in my Eclipse so I can modify the code ?

如何反编译 jar 并将其作为项目加载到我的 Eclipse 中,以便我可以修改代码?

fyi I have googled jar decompiler. Looking for a guide or any insight on experiences with it.

仅供参考,我在谷歌上搜索了 jar 反编译器。寻找指南或任何有关它的经验的见解。

采纳答案by dty

Unless you also have the source code (either in the JAR, or separately), then the best you can do is to use a Java decompiler. Depending on how the code was compiled in the first place, this might generate source code which is significantly different to what the original author wrote (although functionally identical, of course). For example, certain optimizer options could result in loops being re-written and local variables being removed. Certain debug options could result in the names of local variables being removed, so the decompiler will have to invent (meaningless) names for them, etc.

除非您也有源代码(在 JAR 中或单独的),否则您能做的最好的事情就是使用 Java 反编译器。根据最初编译代码的方式,这可能会生成与原始作者编写的代码截然不同的源代码(当然,尽管功能相同)。例如,某些优化器选项可能会导致重写循环并删除局部变量。某些调试选项可能会导致局部变量的名称被删除,因此反编译器必须为它们发明(无意义的)名称等。

I would also question whether what you want to do is legal. Generally, if a project is licensed for modification then its source code will be available and you won't need to do what you're proposing.

我也会质疑你想做的事情是否合法。通常,如果一个项目获得修改许可,那么它的源代码将可用,您无需执行您提议的操作。

回答by jonescb

I've used the Cavaj decompiler and it worked pretty well for me. You can just open up the jar file with any unzipping program like 7zip, .jar files are really just zip files. Then all you need to do is feed the .class files to Cavaj. The .class files are organized by package, so com.foo.Bar will be com/foo/Bar.class inside the .jar

我使用过 Cavaj 反编译器,它对我来说效果很好。您可以使用任何解压缩程序(如 7zip)打开 jar 文件,.jar 文件实际上只是 zip 文件。然后您需要做的就是将 .class 文件提供给 Cavaj。.class 文件是按包组织的,所以 com.foo.Bar 将是 .jar 中的 com/foo/Bar.class

Like Danny said, legality might be questionable depending on the situation. I've only ever used it to look at the source for an older version of an application I wrote but no longer had the source for.

就像丹尼说的那样,根据情况,合法性可能会受到质疑。我只用它来查看我编写的旧版本应用程序的源代码,但不再有源代码。