Extracting jar file in java

Java – Decompile JAR files and view Source Code

In software terms, JAR (Java Archive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file to distribute application software or libraries on the Java platform.

Typically, the contents of any JAR file can be viewed by extracting the JAR file with the help of Tools like 7zip, WinZIP or WinRAR. Once You have successfully extracted the contents of the JAR file, you will get a lot of files with file extension «.class» and these class files are not in human readable format.

So, to overcome this problem and to view the original JAVA source code hidden inside these class files stored inside the JAR file container, we use a tool called JD-GUI.

JD stands for «Java Decompiler«. It is a standalone graphical utility that displays Java source codes of .class files. You can browse the reconstructed source code with the JD-GUI for instant access to methods and fields.

First, we need to download the JD-GUI software:

Java - Decompile JAR files and view Source Code

And You get the home screen like the following:

Java - Decompile JAR files and view Source Code

Click on File — > Open and choose any JAR file of your choice:

Java - Decompile JAR files and view Source Code

After opening JAR file, you will get a window like this:

Java - Decompile JAR files and view Source Code

Now click on the + icon to expand and view the contents of the packages.

NOTE: «.class» files are found inside these packages.

Here, our package is «bruteCUI» and then we get a list of «.class» files. Now click on any class file to view its contents:

Java - Decompile JAR files and view Source Code

You can view the contents and any class files and understand how exactly the java program was coded by the developer. This technique can be used to reverse engineer or to decompile any JAR file.

Extracting the Contents of a JAR File

The basic command, using command line, to use for extracting the contents of a JAR file is:

jar xf jar-file [archived-file(s)]

Let’s look at the options and arguments in this command:

  • The x option indicates that you want to extract files from the JAR archive.
  • The f options indicates that the JAR file from which files are to be extracted is specified on the command line, rather than through stdin.
  • The jar-file argument is the filename (or path and filename) of the JAR file from which to extract files.
  • archived-file(s) is an optional argument consisting of a space-separated list of the files to be extracted from the archive. If this argument is not present, the Jar tool will extract all the files in the archive.

As usual, the order in which the x and f options appear in the command doesn’t matter, but there must not be a space between them.

When extracting files, the Jar tool makes copies of the desired files and writes them to the current directory, reproducing the directory structure that the files have in the archive. The original JAR file remains unchanged.

CAUTION: When it extracts files, the Jar tool will overwrite any existing files having the same pathname as the extracted files.

Let’s extract some files from the TicTacToe JAR file we’ve been using in previous sections. Recall that the contents of TicTacToe.jar are:

META-INF/MANIFEST.MF TicTacToe.class TicTacToe.class TicTacToe.java audio/ audio/beep.au audio/ding.au audio/return.au audio/yahoo1.au audio/yahoo2.au example1.html images/ images/cross.gif images/not.gif

Suppose you want to extract the TicTacToe class file and the cross.gif image file. To do so, you can use this command:

jar xf TicTacToe.jar TicTacToe.class images/cross.gif

This command does two things:

  • It places a copy of TicTacToe.class in the current directory.
  • It creates the directory called images, if it doesn’t already exist, and places a copy of cross.gif within it.
  • The original TicTacToe JAR file remains unchanged.

As many files as desired can be extracted from the JAR file in the same way. When the command doesn’t specify which files to extract, the jar tool extracts all files in the archive. For example, you can extract all the files in the TicTacToe archive by using this command:

Download

You will be to reach the JD GUI’s author site and download from Heelpbook.net this program by login into Heelpbook.net. It’s totally free.

[wpfilebase tag=»file» ]
[wpfilebase tag=»file» ]

Источник

Extracting the Contents of a JAR File

The basic command to use for extracting the contents of a JAR file is:

jar xf jar-file [archived-file(s)] 

Let’s look at the options and arguments in this command:

  • The x option indicates that you want to extract files from the JAR archive.
  • The f options indicates that the JAR file from which files are to be extracted is specified on the command line, rather than through stdin.
  • The jar-file argument is the filename (or path and filename) of the JAR file from which to extract files.
  • archived-file(s) is an optional argument consisting of a space-separated list of the files to be extracted from the archive. If this argument is not present, the Jar tool will extract all the files in the archive.

As usual, the order in which the x and f options appear in the command doesn’t matter, but there must not be a space between them.

When extracting files, the Jar tool makes copies of the desired files and writes them to the current directory, reproducing the directory structure that the files have in the archive. The original JAR file remains unchanged.

Caution: When it extracts files, the Jar tool will overwrite any existing files having the same pathname as the extracted files.

An Example

Let’s extract some files from the TicTacToe JAR file we’ve been using in previous sections. Recall that the contents of TicTacToe.jar are:

META-INF/MANIFEST.MF TicTacToe.class TicTacToe.class TicTacToe.java audio/ audio/beep.au audio/ding.au audio/return.au audio/yahoo1.au audio/yahoo2.au example1.html images/ images/cross.gif images/not.gif

Suppose you want to extract the TicTacToe class file and the cross.gif image file. To do so, you can use this command:

jar xf TicTacToe.jar TicTacToe.class images/cross.gif

This command does two things:

  • It places a copy of TicTacToe.class in the current directory.
  • It creates the directory images, if it doesn’t already exist, and places a copy of cross.gif within it.

The original TicTacToe JAR file remains unchanged.

As many files as desired can be extracted from the JAR file in the same way. When the command doesn’t specify which files to extract, the Jar tool extracts all files in the archive. For example, you can extract all the files in the TicTacToe archive by using this command:

Источник

How to Extract a JAR File

This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene Antonelli is a Technology Writer and Editor for wikiHow. Darlene has experience teaching college courses, writing technology-related articles, and working hands-on in the technology field. She earned an MA in Writing from Rowan University in 2012 and wrote her thesis on online communities and the personalities curated in such communities.

The wikiHow Tech Team also followed the article’s instructions and verified that they work.

This article has been viewed 808,946 times.

JAR (.jar) files are archive files that contain Java class and associated metadata and resources. They are built on the ZIP format. [1] X Research source They are typically executed within a Java environment, but they can also be opened using archive programs like WinZIP, WinRAR, and 7-Zip. This wikiHow teaches you how to extract a JAR file’s contents.

  • Since JAR files work like ZIP files, you can use an archive program like WinRAR to extract them.
  • For Windows users, you can install Java SE to use the ‘jar’ extraction command in the Command Prompt.
  • If you’re a macOS user, you can also install and use Java SE. You’ll use the ‘jar’ command in the Terminal.

Using an Archiving App

Image titled Extract a JAR File Step 1

Install an archive program. JAR files work just like ZIP files. You can use any archive program to extract them. On Windows, you can Install WinRAR 7-Zip, or WinZIP. Macs have their own built-in archive program called Archive Utility. [2] X Research source

Image titled Extract a JAR File Step 2

Find the JAR file you want to extract. Use File Explorer (press Win + E to open File Explorer) or Finder on Mac to navigate to the JAR file you want to extract.

Image titled Extract a JAR File Step 3

Image titled Extract a JAR File Step 4

  • If you don’t see this option, click the JAR file once, then right-click it again and select Open with.

Image titled Extract a JAR File Step 5

Image titled Extract a JAR File Step 6

Click Extract files or Extract here . «Extract files» gives you the option to select a destination to extract the file to. «Extract here» extracts the files to the same location the Jar file is located.

Image titled Extract a JAR File Step 7

Select an extraction location. If necessary, click one of the folders on the right side of the window to select it as the location to which you want to extract your JAR file (WinRAR). If you are using 7-Zip, click the icon with three dots in the upper-right corner and navigate to the folder you want to extract the files to. Then click Ok.

Image titled Extract a JAR File Step 8

Click OK . It’s at the bottom of the WinRAR window. Doing so will extract your JAR file to the selected folder.

Using Java on Windows

Image titled Extract a JAR File Step 9

  • Open the JDK download page.
  • Click the Windows tab.
  • Scroll down and click «https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.exe» next to «Windows x64 Installer».
  • Click the checkbox next to agree to the license agreement and click the green download button.
  • Open the JDK install file and click Yes.
  • Click Next.
  • Click Close.

Image titled Extract a JAR File Step 10

Windows File Explorer

. Click the folder-shaped File Explorer app icon in the taskbar that’s at the bottom of your computer’s screen.

Image titled Extract a JAR File Step 11

Image titled Extract a JAR File Step 12

Select the JAR file’s path. Click a blank space in the address bar at the top of the File Explorer window to do so.

Image titled Extract a JAR File Step 13

Image titled Extract a JAR File Step 14

Windows Start

Image titled Extract a JAR File Step 15

Image titled Extract a JAR File Step 16

Navigate to the JAR file’s path location. To do this type in cd and press the space bar. Then press Ctrl+V to past the file’s path. Then press «Enter»..

Image titled Extract a JAR File Step 17

Image titled Extract a JAR File Step 18

  • If you receive an error message that says «‘jar’ is not recognized as an external or internal command», you need to change the path environment variable to «C:\Program Files\Java\jdk[latest version]\bin» Make sure you replace «[latest version]» with the latest version of Java Development Kit you have installed.

Image titled Extract a JAR File Step 19

Using Java on a Mac

Image titled Extract a JAR File Step 20

  • Open the JDK download page.
  • Click the macOS tab.
  • Scroll down and click «https://download.oracle.com/java/17/latest/jdk-17_macos-x64_bin.dmg» next to «macOS Installer».
  • Open the JDK dmg file.
  • Double-click the JDK pkg file.
  • Click Continue
  • Click Install.
  • Enter your Mac user password and click Install Software.
  • Click Close

Image titled Extract a JAR File Step 21

Mac Finder

Image titled Extract a JAR File Step 22

Image titled Extract a JAR File Step 23

Image titled Extract a JAR File Step 24

Image titled Extract a JAR File Step 25

Mac Spotlight

Image titled Extract a JAR File Step 26

Mac Terminal

. Type «terminal» into the Spotlight text box, then double-click the Terminal icon when it appears. This will open a Terminal window.

Image titled Extract a JAR File Step 27

Type in jar xf and press the space bar. This is the command to extract a JAR file. Don’t press enter just yet, there is still more you need to do.

Image titled Extract a JAR File Step 28

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

Image titled Extract a JAR File Step 29

Community Q&A

I receive an error that jar is not recognized as an internal or external command, operable program or batch file. What do I need to do?

You will need to make sure that the Java JDK is installed. Windows also requires for your environment variables to have a path set to the location of the jar executable. Check your Path Environment Variable under the Advanced System Settings in the Settings Window. Restart your computer when you make changes to your path.

Thanks! We’re glad this was helpful.
Thank you for your feedback.
As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow

I got an error that said java.io.FileNotFoundException (The system cannot find the file specified). What’s up?

Источник

Читайте также:  On blur event in html
Оцените статью