Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dudleybrooks

macrumors member
Original poster
Apr 4, 2011
34
1
San Francisco
I need to make a simple modification in an application (Thunderbird.app) -- changing a single line in a .jar file. On my old Windows computer I knew what software to use. What's the easiest way in Snow Leopard to open, modify, and save the .jar file in the app? Preferably using things that are built into the OS; if not, then using freeware?
 
A .jar file is just a .zip file with a different extension (and some standard/predefined layout). You could use the standard zip and unzip programs in /usr/bin to change a .jar file, assuming it's not signed.

"Changing a single line in a .jar file" doesn't directly make sense in the context of .jar file. If you tell us exactly what you want to do with that .jar file, we might be able to tell you what Mac OS X tools/programs you can use and how.
 
Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; sv-se) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5)

There are really three phases: extraction, modification and assembling it back together.

Extracting is easy: right click and click unarchieve (afaik).

Modification: if it's the manifest (whick class to run and so forth) then it's easy, however the java files are compiled into .class files and will need disassembling before modification.

To piece everything together google the "jar" command for the terminal.

If it's FOSS it's better and easier to compile from source; if not then I don't think it's 100% legit.
 
I need to change a line in a .js file contained in the .jar file. But your reply clarifies my question:

I made this change many, many times under Windows (namely every time I downloaded an upgrade, which, of course, wiped out my previous change). The person who recommended the change also recommended an (un)archiver called IZArc, in which the whole process could be done from inside IZArc -- open (unarchive) the .jar file, find the .js file, edit the line ... and then clicking Quit would return everything to its archived state.

I understand that I can unarchive the .jar with any unarchiver and edit the .js with any text editor. I guess my worry is that, not being a programmer, I might do something harmful in re-archiving -- not archive all the relevant files, or archive too many files, or something.

So my question is: Is there an archiver (hopefully in the OS) which will do all the above from within itself, so that I know that the final .jar contains exactly the files that it should contain? Or, failing that, what do I need to do to make sure that I have re-archived it properly? I realize that in this forum this is a complete newbie question.
 
Well, if .jar files are simply ZIP files with a different extension, then you can zip and unzip them freely from the Terminal using the "zip" and "unzip" commands.
 
Well, if .jar files are simply ZIP files with a different extension, then you can zip and unzip them freely from the Terminal using the "zip" and "unzip" commands.

Or use the 'jar' command, which is written expressly for this purpose, and maintains the correct ordering for manifests (which typically must reside as the first entry, or at most one of the first few).

I'm pretty sure the jar command is installed by default. This should continue to be true on 10.7 Lion, as well.
 
  • Like
Reactions: abronsdilan
Or use the 'jar' command, which is written expressly for this purpose, and maintains the correct ordering for manifests (which typically must reside as the first entry, or at most one of the first few).

I'm pretty sure the jar command is installed by default. This should continue to be true on 10.7 Lion, as well.

Ah, even better. Thanks, didn't know about that.
 
Or you can use the jar command. The parameters are just like the command line zip utilities

$jar -xvf jarfile.jar ** Extracts the files

** edit the file **

$jar -cvf jarfile.jar ** Create the new Jar file
 
  • Like
Reactions: abronsdilan
Thanks. PilotError's method was straightforward and successful -- no software errors, newbie errors, or even pilot errors. But it still had more steps than I used to need in Windows: switching from Terminal after unarchiving, to the desktop to use an editor (my fault, admittedly, for not knowing the unix editor(s) which I assume Terminal has access to), then back to Terminal to rearchive -- plus the more keystrokes needed for the unix commands. I'd still like to find an editor which does it *all* inside one program, like IZArc did in Windows: ctrl-open, edit, ctrl-close -- zip-zip (pun intended)!
 
Thanks. PilotError's method was straightforward and successful -- no software errors, newbie errors, or even pilot errors. But it still had more steps than I used to need in Windows: switching from Terminal after unarchiving, to the desktop to use an editor (my fault, admittedly, for not knowing the unix editor(s) which I assume Terminal has access to), then back to Terminal to rearchive -- plus the more keystrokes needed for the unix commands. I'd still like to find an editor which does it *all* inside one program, like IZArc did in Windows: ctrl-open, edit, ctrl-close -- zip-zip (pun intended)!

I don't know of any tool that does everything. Frankly, this is the first time I've ever seen anyone ask how to edit a file within a jar on Mac OS, so I'm guessing there isn't a big target market.

You can paste command-lines into Terminal, so just save the commands into a text file, then copy and paste away. No typing needed.

Here's roughly what I would save in the text file:
Code:
jar -xvf jarfile.jar  ## Extracts the files

open -e path/to/fileYouWantToEdit.itsExtension

jar -cvf jarfile.jar ## Create the new Jar file
You should obviously change the jarfile.jar to the actual jar file you have.

I've shown ## because those are the actual comment character for bash.

I've also shown an 'open -e' command with a pathname you will have to substitute. The open -e will open the named file in TextEdit.app. If you have another editor you prefer instead, you can tell 'open' to use it instead. Here's the man page for the 'open' command:
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/open.1.html
Look at the -a and -b options in particular.

Finally, you can put other commands in there, such as a 'cd someDir' or whatever else you want.

You could probably write a 'sed' script to do the replacement, so you wouldn't have to manually edit the file at all. Then you could make the whole thing into a shell script, wrap that into an AppleScript and save it as a droplet. Then in future, you simply drop your original app onto the AppleScript droplet and it would do all the changes automatically. You'd have to write and debug all that stuff, though, and it would probably take hours more time than just doing a copy/paste when the app gets updated.

If the change to the jar is something the vendor should provide, you should probably file a bug-report against the app. Because the cleanest fix is to not have to fix it yourself at all.
 
On windows, you can use programs like pkzip or winzip that show the contents in the window and you can just double click a file which then gets extracted under the hood and sent to the associated program (editor).

There are zip utilities under OS X, but admittedly, I don't use OS X like I use windows. I'm sure you could track one of the programs down that will allow you to do the same thing, but for what was needed here, it wasn't worth searching for it.
 
PilotError and Chown33: I'm sure you're right about the lack of market in OS X.

Chown33: Thanks for the advice about automation and the details involved. I will try them. OMG, I might become a programmer!

It's something *I* think should be fixed, but it's not a bug: Thunderbird has an Advanced Search facility for e-mail addresses, which might return multiple addresses. If you click Write, it puts them all into "To" fields (with no other option). The change makes it put them into "BCC" fields, for better netiquette. TB 1.x used to have this option, but lost it in 2.x.
 
Emacs will do what you want

On Linux and Mac OS X I use emacs to edit files within a jar. Just type:

emacs somejar.jar

You can then browse all the files in the jar, open, save, whatever using standard emacs commands. Any changes you make will automatically be applied to the jar (no need to manually unjar anything)
 
  • Like
Reactions: abronsdilan
argh. it doesn't work. I need to replace a few string in the .class files (I use exactly the same number of symbols), then I try to repack it with jar command, but the resulting file is a few bytes smaller than the initial one, and when I try to install it on my mobile it says 'wrong jar format'.
Any ideas?
 
You can use vim editor to edit the files in any compressed text files.
  1. Navigate to file location from terminal.
  2. Type vim name.jar
  3. Select the file you want to change and hit “Enter”
  4. Edit the file and press “Esc” and “:wq!” to save and quit.
Hope this helps.
 
You can use vim editor to edit the files in any compressed text files.
  1. Navigate to file location from terminal.
  2. Type vim name.jar
  3. Select the file you want to change and hit “Enter”
  4. Edit the file and press “Esc” and “:wq!” to save and quit.
Hope this helps.
can't we automate this using a bash? it'd be much helpful if you enlighten through it.
 
  • Like
Reactions: abronsdilan
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.