Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you Edit .jar/archive contents inline with emacs

Tags:

emacs

I know you can navigate the contents of an archive with emacs. Is there a way you can edit those files in place and write the archive transparently?. Currently, I navigate into the archive, write the file to a temp directory, and the use the java jar command to add the file back into the archive. Its a little bit of pain.

P.S. I know there are few use cases where you'd want to do this, but I've inherited a platform that I can't readily modify where I have to cope with this limitation in the short term.

like image 654
nsfyn55 Avatar asked Apr 18 '11 22:04

nsfyn55


People also ask

How do you overwrite a class in a JAR file?

JAR files are just ZIP files. Use a tool like WinZip to extract all the files from the JAR, replace the . class file with yours, recreate the ZIP file using e.g. WinZip, rename it to . jar, overwrite the original JAR file.


2 Answers

Yes, it just works. Did you try it?

I grabbed a jar file that contained a text file and some java code that would print it out. I edited the txt file within the .jar and saved the text file. It did exactly what I would expect.

EDIT- When saving the archive make sure you use C-x C-s

like image 192
Dustin Avatar answered Sep 24 '22 10:09

Dustin


In emacs-23.2 (not 23.1 or 23.3) this doesn't "just work" on Windows due to a bug. Instead it just writes caution: filename not matched: "<internal path>.

One solution is to simply upgrade to 23.3.

To fix the bug in emacs-23.2, open $EMACS_HOME/lisp/arc-mode.el and replace:

(if (equal (car archive-zip-extract) "unzip")
     (shell-quote-argument name)
       name)

with:

name

and recompile:

M-x byte-compile-file $EMACS_HOME/lisp/arc-mode.el

This answer comes from the original emacs bug report.

like image 22
Chadwick Avatar answered Sep 25 '22 10:09

Chadwick