11

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?

6 Answers 6

18

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

2

Sourceforge has links to the source.

7
  • 1
    I did search sourceforge but mostly what I got was setup files.
    – A User
    Jun 30, 2012 at 3:32
  • What's the link to the project you downloaded?
    – Naddiseo
    Jun 30, 2012 at 15:52
  • Here: sourceforge.net/projects/ezim/?source=directory See if you can decompile it :)
    – A User
    Jun 30, 2012 at 18:56
  • No need. There's a link to the source under the "code" menu. If you view the code, there's an option to download a tarball: ezim.svn.sourceforge.net/viewvc/ezim
    – Naddiseo
    Jun 30, 2012 at 20:59
  • I tried downloading tarball but all it does is keep downloading and downloading
    – A User
    Jul 1, 2012 at 4:42
2

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.

1

do you have eclipse in your computer?you can add the jar file to a project,then you can see the source code

1
  • 1
    This is actually incorrect, you can see class code. Oct 25, 2018 at 17:49
0

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

-1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.