1

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,

Odinulf

2
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
myjar.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.

  • 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: stackoverflow.com/questions/2591516/… - got any suggestions? – Odinulf Feb 24 '12 at 0:31
  • 1
    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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .