17

I am trying to view the content of a .war file. I first did set its permissions with chmod 777 then when I try to accces it using:

cd /usr/local/standalone/deployments/Sample.war/WEB-INF/classes/

It is giving cd: /usr/local/standalone/deployments/Sample.war/WEB-INF/classes/: Not a directory and I am not able to proceed further.

Can someone help me in this issue?

3
  • 5
    Don't use chmod 777 on a compressed file. You don't need execution bit for reading it. A safe 644 or 640 is recommended.
    – Braiam
    Jul 23 '13 at 11:31
  • See the official Java docs: docs.oracle.com/javase/tutorial/deployment/jar/view.html
    – slm
    Jul 23 '13 at 13:31
  • Is /usr/local/standalone/deployments/Sample.war a directory or a file ?
    – jlliagre
    Jul 23 '13 at 14:16
21

.war files are packed. You can extract the information by using either of the following commands:

jar -xvf Sample.war
unzip Sample.war

You should then be able to run cd /usr/local/standalone/deployments/Sample.war/WEB-INF/classes/

3
  • 3
    jar -xvf *war won't work if there is more than one war file in the current directory. tar -xvfz won't work at all, you are confusing gzipped files and zipped ones.
    – jlliagre
    Jul 23 '13 at 14:14
  • This is true, I didn't mean to infer that it would work with multiple wars, just that you could use that command verbatim for any one war. I've changed it
    – JZeolla
    Jul 23 '13 at 14:48
  • 1
    I think it's better to use jar -tvf and not the proposed jar -xvf way. So files aren't extracted (and contaminate your .) but just listed.
    – Dror Cohen
    Mar 31 '15 at 9:52
8

.war files are zipped archives.

You can list what they contain with either

jar tvf Sample.war

or

zipinfo Sample.war

Should you want to see the content of files stored in an archive, you need to first extract it somewhere:

mkdir /tmp/foo
cd /tmp/foo
unzip /usr/local/standalone/deployments/Sample.war
ls -l WEB-INF/classes/
5

If you don't want to extract the file you can use vim filename.war to read the contents of the file. You can read subdirectories of files by selecting them and pressing enter.

1
  • For this to work, you need the package unzip installed.
    – Thaoden
    Jun 2 '17 at 8:52
1

First you have to extract the war file jar xvf Sample.war. Then you can cd in to the war file.

1

If the unix commands does not work, ftp the file to local machine.

.jar or .war or .ear any archive file can be opened in 7-Zip by following the steps below -

  1. Right click the archive file
  2. 7-Zip
  3. Open archive

You should be able to see all the archive file contents. Now browse through the folder/file and then right click -> edit the file -> save the file.

0

Besides extracting them with jar or unzip, you can also use the Midnight Commander (mc) and navigate to these files and press Enter on them as if they were directories.

If this doesn't immediately work, your flavour of mc is not configured to know the .war suffix, but you can still use this feature by typing either cd Sample.war#uzip (old mc) or cd Sample.war/uzip:// (mc in Debian unstable) and pressing Enter. As an added benefit, pressing Escape then Enter (in some terminals, also Alt-Enter but this is not portable so don’t depend on it) inserts the current filename into the command line, but you’ll have to press Backspace too because it adds a space, and the #uzip or /uzip:// needs to immediately follow the filename.

This is known as the mc VFS (virtual filesystem).

I won’t repeat the unzip/fastjar/jar answers here, but they’re also correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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