0

I have a jar file which is copied from a windows machine onto unix machine....usually we convert all the files that were copied from windows using dos2unix command.. When I convert the jar file to unix format using dos2unix...I am getting the below error...

Exception in thread "main" java.io.IOException: Error opening job jar: hadoop-examples-2.0.0-mr1-cdh4.3.0.jar
        at org.apache.hadoop.util.RunJar.main(RunJar.java:135)
Caused by: java.util.zip.ZipException: invalid END header (bad central directory offset)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:127)
        at java.util.jar.JarFile.<init>(JarFile.java:135)
        at java.util.jar.JarFile.<init>(JarFile.java:72)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:133)

It ran successfully before running dos2unix command on it... Any idea why this happened ?

disizjay
  • 23
  • 2
  • 10
  • 2
    the conversion just turn 0d0a in 0a... and so you had a zipped file that had that sequence, and you corrupted it. – Jekyll Nov 21 '13 at 19:20

1 Answers1

6

Don't do that. A jar file is the same as a zip, it's a binary. dos2unix is for converting line endings in ASCII files (not binary).

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • I have another jar file I ran dos2unix on it and it working... Why this is happening for some jar's..not all jars Some jar files are working after dos2unix and some are not...Why is that ? – disizjay Nov 21 '13 at 19:53
  • The problem for us is like we have an automated script which convert all the files into dos2unix format.....After conversion some jar files are running fine and some are not....We are trying to figure out the problem – disizjay Nov 21 '13 at 19:55
  • Because the byte sequence `0D 0A` is not present in all binary files. `0D 0A` (aka '\r\n'), is a carriage-return character followed by a new-line character. dos2unix replaces that sequence with `0A` - or just new-line, because dos and unix use different line ending conventions. – Elliott Frisch Nov 21 '13 at 19:58
  • Run `file` on the files. If it's a binary, don't do that. – Elliott Frisch Nov 21 '13 at 19:59
  • When I do file on a jar files some files giving me the following Zip archive data, at least v1.0 to extract and some are Zip archive data, at least v2.0 to extract what that mean ? It doesn't really say binary or ASCII.... – disizjay Nov 21 '13 at 20:21
  • $ file something.jar ----Zip archive data, at least v1.0 to extract $ file somethingelse.jar ----Zip archive data, at least v2.0 to extract ---What does it mean ? It doesn't really say binary or ASCII.... Sorry previous comment was not properly formatted... – disizjay Nov 21 '13 at 20:32
  • `$ if [ "$(file ${THE_FILE} | grep ASCII | wc -l)" == "1" ]; then dos2unix "${THE_FILE}"; fi` – Elliott Frisch Nov 21 '13 at 23:24