-
-
Save briandealwis/782862 to your computer and use it in GitHub Desktop.
One-liner to turn jar with Main-Class into executable shell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# turn a jar with a Main-Class into a stand alone executable | |
(echo '#!/usr/bin/env java -jar'; cat blahblah.jar) > blah | |
# turn a jar with a particular main clas into a stand alone executable | |
(echo '#!/usr/bin/env java -jar package.MainClass'; cat blahblah.jar) > blah |
Thanks for your help regarding Linux..
Beware of typo.. the command should look like
(echo '#!/usr/bin/java -jar'; cat blahblah.jar) > blah
Thanks.
Doesn't seem to work any more ๐ Which is strange as jar tf file
shows the jar contents.
This worked for me, both in mac os and in a linux docker image.
It's working for me too. I really should have included some detail such as the OS and JVM versions that I encountered the problem.
/me blushes
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This unfortunately doesn't work in Linux though it works great on my Mac. Linux interprets everything after the interpreter in the shebang as one big argument. So, env ends up getting "java -jar" as the exe.
While not as portable, this slight modification works. Does require java to be in /usr/bin though. :-P
(echo '#!/usr/bin/java -jar'; car blahblah.jar) > blah
NOTE: Edited (12 years later ๐) to fix typo @mhewedy mentioned.