Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Currently I'm attempting to compress a decompressed jar file that I have changed into a jar file. How can I do this via the command line? I know that there is a jar command in terminal, I'm just having trouble learning how to compress that folder.

If the folder's directory (probably not correct term, but hopefully you get the idea) is /Users/Odinulf/folderone/foldertwo (foldertwo is directory that I want compressed), what would be the exact code to do this?

Thanks in advance,


share|improve this question
up vote 2 down vote accepted
cd /Users/Odinulf/folderone
jar cvf myjar.jar foldertwo

For example:

/Users/ian/code/tmp [ian@Ian-Cs-MacBook-Pro] [19:13]
> jar cvf myjar.jar 8779 
added manifest
adding: 8779/(in = 0) (out= 0)(stored 0%)
adding: 8779/.DS_Store(in = 6148) (out= 355)(deflated 94%)
adding: 8779/logs/(in = 0) (out= 0)(stored 0%)
adding: 8779/logs/MasterLog.txt(in = 3044043) (out= 207357)(deflated 93%)
adding: 8779/logs/StartLog.txt(in = 6984480) (out= 685836)(deflated 90%)
/Users/ian/code/tmp [ian@Ian-Cs-MacBook-Pro] [19:13]
> ls *.jar

Breaking it down, the options are:

  • c - create a jar file
  • v - be verbose when you do it
  • f - put the bitstream in to a file instead of standard out

Then you give it the file to put the bitstream in to. In this case myjar.jar. And then you give it a list of directories and files to put in to that jar bitstream. Relative and absolute pathing for contents is generally maintained so be careful with that.

share|improve this answer
Thanks a ton :D – Odinulf Feb 24 '12 at 0:25
Just another quick question: I get this error when I try to open the jar Failed to load Main-Class manifest attribute from [jar file path] – Odinulf Feb 24 '12 at 0:28
Googled it quickly... got this:… - got any suggestions? – Odinulf Feb 24 '12 at 0:31
Yes, you need to create a manifest.txt file for your Jar file according to the to answer in that SO question you found. That'd be a Java question and it's veering in to off-topic for Ask Different. – Ian C. Feb 24 '12 at 0:41
Update: I just used jar cvfm, and it worked fantastically. Thanks for your help :D – Odinulf Apr 3 '12 at 2:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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