简体   繁体   中英

Using Java Decompiler (JD-GUI) on a .class file gives me multiple errors on src file, but it runs fine within a .jar? How does it work?

I'm new to Java and I'm trying to understand something. I managed to get a.jar file for a local device to communicate with my laptop. It works fine, but I would like to do an upgrade and scoop around the codes and change some details. I used a Java Decompiler on the.jar file and managed to take a look at the class files. However, whenever I decompile them into source codes, errors will occur in my IDE, and I'm unable to build them. What exactly happened? If it's working fine in the.jar why does it produce errors?

Compilation is a lossy process, so decompilation is always a "best effort" endeavor. Java bytecode is unusually high level, so Java decompilation is relatively easy compared to other languages, but it will still never be 100% complete. Therefore, you should not be surprised to see errors when re-compiling decompiled source.

If you want to work directly with bytecode, I would recommend using the Krakatau disassembler and assembler . Instead of decompiling to Java source, the disassembler converts bytecode into a human readable assembly format which is specifically designed to be converted to and from bytecode losslessly. However, it requires a good understanding of low level Java bytecode to use.

Completely agree with Antimony. There is no decompiler which decompiles always without any error. Sometimes it decompiles well, sometimes not.
The best way is to have several decompilers and use them each by other to decrease errors in decompiled source.
If you use Eclipse I would suggest https://marketplace.eclipse.org/content/enhanced-class-decompiler
If you use IntelliJ try this decompiler Jar Explorer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM