Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract the source code from a *.jar file on a Mac?

I'm very confused. I downloaded a *.jar file as a bit of software. So, I would like to extract the source code to look at it

I used the command jar xf filename.jar

which returned two more *.jar files and a *.class file. I still cannot open these in the terminal with standard text editors.

Perhaps this is not open source software? Is there an alternative to see what has been done here?

like image 635
ShanZhengYang Avatar asked Sep 19 '16 00:09

ShanZhengYang


People also ask

How do I unpack a jar file on a Mac?

Press ⌘ Command + V to paste in your JAR file's path, and press ⏎ Return . This executes the command to extract the JAR file. Go back to the JAR file's location.

Can we extract source code from jar file?

Jar files are archive files that contains of a lot of different java classes (files). You can use winzip/winrar to open the jar files and you can see those java classes in jar files. Typically you can use a Java decompiler to decompile the class file and look into the source code.

How do I find the source code of a jar file?

The JD-GUI is a nice open-source GUI utility to explore Java source code decompiled by the Java decompiler JD-Core. When we see the main window of JD-GUI, we can either open our JAR file by navigating the menu “File -> Open File…” or just drag-and-drop the JAR file in the window.

Can you run a .jar on Mac?

To run a JAR file on Windows, Mac or Ubuntu machines, follow these steps: Verify that Java is installed on your computer. Confirm the computer's PATH variable includes Java's \bin directory. Double-click the JAR file if auto-run has been configured.


2 Answers

  • Download FernFlower.jar: http://the.bytecode.club/fernflower.jar
  • Documentation: http://the.bytecode.club/fernflower.txt
  • Repository: https://github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler

Run "java -jar fernflower.jar -dgs=true JarToDecompile.jar DecompiledJar"

This is what Intelli-J & Android-Studio Decompiler does.

Note: Fernflower extracts the .java files to a .jar file. You can either Unzip the jar file as a regular zip file (if your version of Archive Utility on OSX allows it -- It doesn't do it for me on OSX Sierra but works on El Capitan) OR you can do jar xf DecompiledJar and it'll extract it.

Example (all in one command -- multiple commands separated by &&):

java -jar fernflower.jar -dgs=true JarToDecompile.jar DecompiledJar && cd DecompiledJar && jar xf DecompiledJar.jar && cd ../

like image 102
Brandon Avatar answered Sep 23 '22 04:09

Brandon


Easy solution:

If you have eclipse just add the jar file in the classpath of current project u can see all the packages and source code in the jar. You no need to install and use the commands. You will get a better view of all files

like image 41
saravanan saminathan Avatar answered Sep 22 '22 04:09

saravanan saminathan