8

On an Amazon Linux instance I'm trying to edit a jar file remotely through putty. vim provides a convenient navigator, which displays a prompt with a list of the contained files in the jar:

> vim filename.jar

" zip.vim version v22
" Browsing zipfile /home/ec2-user/tigase/libs/tigase-muc.jar
" Select a file with cursor and press ENTER

      453  01-14-2013 10:01   META-INF/MANIFEST.MF
      110  01-14-2013 10:01   META-INF/maven/tigase/tigase-muc/pom.properties
     4675  01-14-2013 10:01   META-INF/maven/tigase/tigase-muc/pom.xml
     5751  01-14-2013 10:01   tigase/component/AbstractComponent.class
     2337  01-14-2013 10:01   tigase/component/AbstractComponent$1.class
     ....

However after selecting a file (eg. AbstractComponent.class) and press Enter, within vim I get:

caution: filename not matched:       5751  01-14-2013 10:01   tigase/component/AbstractComponent.class

and the file doesn't open.

As a side note, I also noticed that if I extract the jar (either with unzip or jar) and open an extracted file with vim, the contents are misformatted:

Êþº¾^@^@^@2^A^[^H^@     ^H^@
^H^@^K^H^@^U^H^@^V^H^@!^H^@#^H^@^^A^@) stanza already with type='...
^A^@^C()I^A^@^C()V^A^@^C()Z^A^@^F<init>^A^@^NDEFAULT_WRITER^A^@^WFE...
....

Any ideas how to overcome the error or formatting issue?

  • 2
    You are aware that jar is basically a zip, and that .class files are Java bytecode files? Meaning they're not text files, but inly data containers and you'd need a decompiled (or a hex editor and a steady eye) to read them. – Bobby Feb 5 '14 at 10:04
4

However after selecting a file (eg. AbstractComponent.class) and press Enter, within vim I get:

caution: filename not matched

This is probably a known bug in vim's ZIP plugin - the plugin does not properly handle ZIP files that contain ZIP comments. See e.g. this mailing list post

As a side note, I also noticed that if I extract the jar (either with unzip or jar) and open an extracted file with vim, the contents are misformatted

This is because most files inside a JAR are compiled Java class files (file suffix .class). These are binary data, and vim is not really suitable for editing them, because vim is a text editor, not a binary editor.

You can edit them in vim using the xxd command (see "Using xxd" in the vim docs), or you can use a hex editor, such as bvi.

At any rate, directly viewing the contents of a class file is rarely helpful, as you need to understand the binary class file format to read them.

Could you explain why you are trying to open files inside a JAR? Then maybe we can help.

| improve this answer | |
  • 'grats on 10k!~ – Sathyajith Bhat Feb 5 '14 at 12:17
  • I had apparently spaced out thinking of .java as of .class (compiled binaries) and expecting to be able to edit those files directly, i.e. not needing to extract - edit - compress. I will look up and try 'xxd', thanks a bunch! – ile Feb 5 '14 at 12:23
  • @Sathya: Thanks, I just got the message :-). – sleske Feb 5 '14 at 14:41
1

This is how I solved the formatting issues.

First install emacs

 yum install emacs

Then use below command to read the content

emacs somejar.jar

select the content and press Enter

To save and quit from the editor, press C-x C-s (Ctrl+x, followed by Ctrl+s).

Source : How To Use the Emacs Editor in Linux

| improve this answer | |
  • 4
    The question is about how do this job with vim. – artificerpi Jul 11 '17 at 7:17
  • This answer is not on topic, doesn't help the community, and follows the pattern: have one (small?) problem with X — plz switch and start using Y. – kgadek Dec 31 '18 at 11:57

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.