Unzip jar in linux

Extracting .jar file with command line

To extract the files from a jar file, use x , as in:

To extract only certain files from a jar file, supply their filenames:

C:\Java> jar xf myFile.jar foo bar 

The folder where jar is probably isn’t C:\Java for you, on my Windows partition it’s:

C:\Program Files (x86)\Java\jdk[some_version_here]\bin 

Unless the location of jar is in your path environment variable, you’ll have to specify the full path/run the program from inside the folder.

EDIT: Here’s another article, specifically focussed on extracting JARs: http://docs.oracle.com/javase/tutorial/deployment/jar/unpack.html

Ok, When I do that jar xf. command, I get the error: ‘jar’ is not recognized as an internal or external command,operable program or batch file. How do I fix this?

java.io.IOException: META-INF : could not create directory at sun.tools.jar.Main.extractFile(Main.java:928) at sun.tools.jar.Main.extract(Main.java:852) at sun.tools.jar.Main.run(Main.java:242) at sun.tools.jar.Main.main(Main.java:1149) how to remove this error?

@AnilPatel I fixed this by running the command prompt as administrator (right click «run as administrator»)

here’s a stupid question — if I do this right (fixed the error messages I received first time), where are these files going to be extracted to? I’ve checked the jdk folder and the folder of the jar file to extract but I don’t see any new files

Note that a jar file is a Zip file, and any Zip tool (such as 7-Zip) can look inside the jar.

unzip file.jar -d dir_name_where_extracting

You can use the following command: jar xf rt.jar

Where X stands for extraction and the f would be any options that indicate that the JAR file from which files are to be extracted is specified on the command line, rather than through stdin.

Java has a class specifically for zip files and one even more specifically for Jar Files.

java.util.jar.JarOutputStream java.util.jar.JarInputStream 

using those you could, on a command from the console, using a scanner set to system.in

Scanner console = new Scanner(System.in); String input = console.nextLine(); 

then get all the components and write them as a file.

JarEntry JE = null; while((JE = getNextJarEntry()) != null) < //do stuff with JE >

You can also use java.util.zip.ZipInputStream instead, as seeing a JAR file is in the same format as a ZIP file, ZipInputStream will be able to handle the Jar file, in fact JarInputStream actually extends ZipInputStream.

Читайте также:  Количество запросов ping linux

an alternative is also instead of getNextJarEntry, to use getNextEntry

Источник

Are there other options to unzip a file in Ubuntu besides «unzip»? [closed]

Questions must be relevant to professional system administration. Server Fault is a site dedicated to professionals; novice questions are off-topic. Please see the Help Center for more information on topicality. The best advice we can give you is to hire a professional to help you out.

My sysadmin is unreachable right now, and I have a zipped file on the server that I would like to unzip. however, we don’t currently have zip and unzip installed, and I don’t have root access to install them. Am I out of options entirely? Are there other things that can unzip this file?

6 Answers 6

I haven’t tried this, but, there’s a zipfile module in Python’s standard library since version 1.6, and since version 2.6 has had an extractall method

You should be able to do something like:

  1. Create a file with the following contents (editing it to fit your use case).
  2. Save the file as «unzipfile.py»
  3. Run with python unzipfile.py

And it’ll extract test.zip to /home/user/directory .

import zipfile with zipfile.ZipFile('test.zip', "r") as z: z.extractall("/home/user/directory") 

Alternatively, BusyBox contains an unzip «module», and if you could download and run the statically-linked BusyBox, then you could use that to unzip things.

i tried the first part of this and got: The program ‘import’ can be found in the following packages: * imagemagick * graphicsmagick-imagemagick-compat — btw. i didn’t downvote you

You can now just call the module directly from the command line python -m zipfile -e monty.zip target-dir/ (see docs.python.org/2/library/zipfile.html#command-line-interface)

Читайте также:  Vmware workstation logs linux

If you have java installed, the jar command can unzip a zipped file:

Update: OpenJDK is downloadable for Linux as a tar.gz archive installable without root access here: http://jdk.java.net/17/

The Windows version is however a zip file so that wouldn’t help on that OS.

The program ‘jar’ can be found in the following packages: * default-jdk * fastjar * gcj-4.6-jdk * openjdk-6-jdk * gcj-4.5-jdk * openjdk-7-jdk Ask your administrator to install one of them 🙁

I am a little scerred to install anything on the server, for fear of the wrath of my sysadmin, but i will definitely try this if need be.

BSD / Mac OSX

The tar utility that ships with Mac and BSD derivatives, support extracting zip archives from the tar command

tar -xvf foo.zip tar --version bsdtar 2.8.3 - libarchive 2.8.3 

Debian / RHEL

The tar archive that ships with Ubuntu and others does not support extracting zip files. The best option will be to scp the file to a machine with zip installed.

tar -xvf foo.zip tar: This does not look like a tar archive tar: Exiting with failure status due to previous errors 
echo "the quick brown fox jumped over the lazy dog" > bar.txt zip -r bar.zip bar.txt rm bar.txt tar -xvf bar.txt cat bar.txt the quick brown fox jumped over the lazy dog 

Rewrote answer to clarify that tar -xvf only works on bsd OS’s. While it is good information, It will not work in this scenario after all.

Источник

Linux: what is a most convenient way to see the content of .jar file

What is a most convenient way to see the content of .jar file w/o using unzip/untar commands? What I’d like to do — is to browsing inside using cd command like it is the usual folder, seeing content, size of classes — ‘ls -la’ . MC allowed to do so on the fly. Is there are any ease-in-use alternative?

Читайте также:  Making directory in linux

@ekaj less and unzip doesnt help me — it doesn’t show me the size of files in the archive for example, or date&time of last modification (unless I’ll decompress it somewhere to /tmp/AAA and then will run ls -la against /tmp/AAA — which is what I want to avoid).

@javagirl: unzip -l does show you the size of files in the archive and date & time of last modification without unpacking the package. See my answer below. Actually, this is a duplicate as ekaj suggested.

8 Answers 8

Use the jar tool that comes with the Java SDK for listing contents of a jar file. As described in http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jar.html

Use vim to view and edit the contents of a jar file without extracting:

Open the jar in vim like this:

You are presented with a list of files:

1 " zip.vim version v22 2 " Browsing zipfile /var/www/sandbox/eric/rabbitmq-client.jar 3 " Select a file with cursor and press ENTER 4 5 META-INF/ 6 META-INF/MANIFEST.MF 7 com/ 8 com/rabbitmq/ 9 com/rabbitmq/client/ 10 com/rabbitmq/client/impl/ 11 com/rabbitmq/client/impl/recovery/ 12 com/rabbitmq/tools/ 13 com/rabbitmq/tools/json/ 14 com/rabbitmq/tools/jsonrpc/ 15 com/rabbitmq/utility/ 

Put the cursor over the META-INF/MANIFEST.MF and press Enter . You see this:

Manifest-Version: 1.0 Ant-Version: Apache Ant 1.8.2 Created-By: 1.6.0_31-b31 (Sun Microsystems Inc.) Export-Package: com.rabbitmq.client;version="3.3.5";uses:="com.rabbitm q.client.impl,com.rabbitmq.utility,javax.net,javax.net.ssl,javax.secu rity.auth.callback,javax.security.sasl",com.rabbitmq.client.impl;vers ion="3.3.5";uses:="com.rabbitmq.client,com.rabbitmq.utility,javax.net ",com.rabbitmq.client.impl.recovery;version="3.3.5";uses:="com.rabbit mq.client,com.rabbitmq.client.impl",com.rabbitmq.tools;version="3.3.5 ";uses:="com.rabbitmq.utility",com.rabbitmq.tools.json;version="3.3.5 ",com.rabbitmq.tools.jsonrpc;version="3.3.5";uses:="com.rabbitmq.clie nt",com.rabbitmq.utility;version="3.3.5" Bundle-Vendor: SpringSource Bundle-Version: 3.3.5 Tool: Bundlor 1.0.0.RELEASE Bundle-Name: RabbitMQ Java AMQP client library Bundle-ManifestVersion: 2 Bundle-SymbolicName: com.rabbitmq.client Import-Package: javax.net;version="0",javax.net.ssl;version="0",javax. security.auth.callback;version="0",javax.security.sasl;version="0" Name: rabbitmq-client Specification-Title: AMQP Specification-Version: 0.9.1 Specification-Vendor: AMQP Working Group (www.amqp.org) Implementation-Title: RabbitMQ Implementation-Version: 3.3.5 Implementation-Vendor: Rabbit Technologies Ltd. (www.rabbitmq.com) 

Change a few lines using normal vim editing commands.

press 'i' to enter insert mode edit your lines press :wq to write and quit 

You are taken back to a list of files in the jar, quit out.

Check to see if it the changes are permanent:

Follow the above steps again to inspect the file again, the change should still be there. 

Источник

Оцените статью
Adblock
detector