I downloaded jgit packed in sh file and ran it in mingw. I watched in process list that java process was started just with main class and parameters

"c:\Program Files\Java\jdk1.6.0_26\bin\java.exe" org.eclipse.jgit.pgm.Main diff master

I checked process current directory for unpacked main class, there was nothing! Where is main class located on file system?


It sets the class path to the path of the .sh file in line 88 of the .sh file.

this_script=`which "$0" 2>/dev/null`
[ $? -gt 0 -a -f "$0" ] && this_script="$0"



There's no need to "unpack" the main class.

It uses a trick to combine a shell script and the actual JAR/ZIP data in a single file: It uses the fact that a ZIP file's central data structure is at its end. The zip/jar file reader simply about the "garbage data" shell script at the beginning.

Often the first thing in a zip file is a zip entry, which can be identified easily by its signature. But it is not necessarily the case that a zip file begins with a zip entry, and is not required by the zip specification.

As long as the shell script code exits before the actual zip/jar data starts, the shell doesn't care about the "garbage data" after the shell script part of the file either.

  • Java process can directly read from sh file? – misha nesterenko Jan 14 '12 at 12:06
  • @mishanesterenko It's not an .sh file. It's a combination .sh/.jar file. See my edited answer. – Daniel Beck Jan 14 '12 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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