9

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?

ile
  • 213

2 Answers2

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.

sleske
  • 23,525
-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

John Joe
  • 151