简体   繁体   中英

How to view the source code inside a JAR file?

I downloaded the code for a LAN messenger from sourceforge. It is an executable JAR file.
You double-click it and your messenger starts.

I want to study the source code. How do I do that?

Extract source code from .jar file

(1)Use JD GUI ( http://jd.benow.ca/ ). Open the application, drag and drop your JAR file into it.

(2)You can extract a jar file with the command :

jar xf filename.jar

References : Oracle's JAR documentation

Sourceforge 有指向源的链接。

Opening JAR files works with any software that supports the .ZIP file format, like WinRAR.

But if you want to access the source code, it gets a little tricky as in a JAR file, the Java code is already "precompiled" into Java's byte code. Fortunately, there is a (rough) way of decompiling byte code back to (usually) readable Java source code.

There are many programs that do this, my personal favorite is JAD ( http://www.varaneckas.com/jad/ ).

Since you found the project on sourceforge, it is likely the code is not obfuscated. Although, if it is, you can still decompile it, but it is likely to be very hard to read and comprehend.

你电脑里有eclipse吗

IntelliJ is awesome at this type of thing. Just open like you would any other project, and it will decompile it for you.

Only two options available 1. Use decompiler tool like Cavaj or JAD. Source might be hard to make changes to. If it for understanding the funactionality it might help. 2. SourceForge should have link to source files too. I guess it is worth trying luck to check it again on SourceForge.

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