Is there a way to extract the source code from an executable .jar file (Java ME)?
-
3But note that doing this may be illegal depending on whether you own the copyright to the jar, the country you live in and your purpose for doing it. – Richard Feb 24 '11 at 16:14
-
2If it is open source, get the source from the developer. Otherwise "Any compliance with the EULA will be appreciated". – Andrew Thompson Feb 24 '11 at 16:31
-
Check procyon decompiler. Download it's jar to decompile jar files. I have given steps below – nitin angadi Dec 10 '19 at 00:32
11 Answers
Use JD GUI. Open the application, drag and drop your JAR file into it.
-
9
-
@ZulqurnainJutt use as mentioned in @elachance's answer `jar xf filename.jar` – Arvind Sridharan Sep 14 '18 at 04:45
-
You can extract a jar file with the command :
jar xf filename.jar
References : Oracle's JAR documentation

- 11,812
- 19
- 76
- 129

- 917
- 6
- 5
-
24This is equivalent to renaming `filename.jar` to `filename.jar.zip` and then just unzipping it. – Mathias Bynens Mar 05 '14 at 09:16
-
43This doesn't extract the source code. It extracts the compiled source code. – 0xcaff Jul 22 '15 at 20:35
-
5@caffinatedmonkey it does extract source code when the jar contains java files, e.g. jars with names typically ending in "-sources". It indeed does only extract .class files when the jar does not contain any java source files. – edwardmp May 02 '16 at 09:04
I believe this can be done very easily. You can always extract the source files (Java files) of a jar file into a zip.
Steps to get sources of a jar file as a zip :
- Download JAD from http://techieme.in/resources-needed/ and save it at any
location on your system. - Drag and drop the jar for which you want the sources on the JAD. 3 JAD UI will open with all the package structure in a tree format.
- Click on File menu and select save jar sources.
- It will save the sources as a zip with the same name as the jar.
Hope this helps.
The link is dead due to some reason so adding the link from where you can download the JDGUI

- 5,518
- 9
- 31
- 50

- 7,882
- 15
- 65
- 93
-
1@Nitesh... I will be posting the link hosted on my website... please download it from there – dharam Aug 28 '13 at 11:28
-
4
-
After saving all sources, when I open the Java files, it shows all the lines as commented lines. Is there any setting to fix that? – Anand Jul 23 '20 at 10:39
Your JAR may contain source and javadoc, in which case you can simply use jar xf my.jar
to extract them.
Otherwise you can use a decompiler as mentioned in adarshr's answer:
Use JD GUI. Open the application, drag and drop your JAR file into it.

- 498
- 3
- 10
- 28

- 44,826
- 10
- 98
- 87
-
21Note that .jar files are actually .zip files and can be opened with any ZIP tool. – Chris Nava Feb 24 '11 at 17:50
I know it's an old question Still thought it would help someone
1) Go to your jar file's folder.
2) change it's extension to .zip.
3) You are good to go and can easily extract it by just double clicking it.
Note: I tested this in MAC, it works. Hopefully it will work on windows too.

- 3,001
- 4
- 34
- 59
-
2@JCodex, I'm doing a research project on the sentiment analysis tool "opinionfinder" and its jar does indeed contain both java AND class files. so your comment is not 100% true. I know it would usually contain only .class but not in this case at least – wired00 Mar 04 '15 at 10:36
-
4
-
Seems JD-GUI is a multi-platform tool that actually decompiles the code and shows the source code for classes in all packages. I tried it and could get the source code in a second in MacOS. I have Java 8 installed . You can get it on http://jd.benow.ca Not sure if it works for large projects. – Carlos Sá Sep 01 '17 at 10:03
-
1need source code which is not provide by the way you described – chiragchavda.ks Jun 28 '19 at 10:53
Do the following on your linux box where java works (if u like the terminal way of doing things)
cd ~
mkdir decompiled_code && cd decompiled_code
// download jar procyon from https://drive.google.com/file/d/1yC2gJhmLoyE8royCph5dLEncgkNZXj58/view?usp=sharing
java -jar procyon-decompiler-0.5.36.jar /Path/to/your/jar -o .
NOTE : as @Richard commented "this may be illegal depending on whether you own the copyright to the jar, the country you live in and your purpose for doing it."

- 382
- 5
- 10
-
For a specific class file you can do java -jar procyon-decompiler-0.5.36.jar /Path/to/your/jar package/of/the/java/class.class > className.java – nitin angadi Jan 06 '21 at 06:40
Steps to get sources of a jar file as a zip :
Download JD-GUI from http://java-decompiler.github.io/ and save it at any location on your system.
Drag and drop the jar or open .jar file for which you want the sources on the JD.
Java Decompiler will open with all the package structure in a tree format.
Click on File menu and select save jar sources. It will save the sources as a zip with the same name as the jar.
Example:-
We can use Eclipse IDE for Java EE Developers as well for update/extract code if require.
From eclipse chose Import Jar and then select jar which you need. Follow instruction as per image below

- 2,457
- 2
- 21
- 38
AndroChef Java Decompiler produces very good code that you can use directly in your projects...

- 181
- 12
Above tools extract the jar. Also there are certain other tools and commands to extract the jar. But AFAIK you cant get the java code in case code has been obfuscated.

- 355
- 3
- 18
suppose your JAR file is in C:\Documents and Settings\mmeher\Desktop\jar and the JAR file name is xx.jar, then write the below two commands in command prompt:
1> cd C:\Documents and Settings\mmeher\Desktop\jar
2> jar xf xx.jar

- 25
-Covert .jar file to .zip (In windows just change the extension) -Unzip the .zip folder -You will get complete .java files

- 716
- 9
- 12
-
4As a small note on this method... It is true that jar files are fancy zip files. However, unziping a jar will most likely yield *.class files, that is "compiled" java files. It is possible to "decompile" class files to normal java files. This functionality is included in many IDEs – Daniel Hernandez May 21 '18 at 13:38
-