Created
March 2, 2018 21:53
-
-
Save phlash/a5e914430bf017472d6182af4c25fd0f to your computer and use it in GitHub Desktop.
Self-executing single-file Java programs...
This file contains hidden or 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
#!/bin/sh | |
# This self-executing Java program uses the following /embedded shell script/ to compile & execute itself.. | |
# magic constant holding length of script | |
SKIP=26 | |
# parse our name.. | |
FILE=`basename $0 .java` | |
# get some working space, clean up old crud | |
WORK=/tmp/java-hack | |
mkdir -p $WORK | |
find $WORK -mtime 7 |xargs rm -f | |
# transform ourselves to compilable Java (aka, strip the shell script head), save the timestamp | |
tail +$SKIP $0 > $WORK/$FILE.java | |
touch -r $0 $WORK/$FILE.java | |
# compile if required.. | |
[ -r $WORK/$FILE.class -a $WORK/$FILE.java -ot $WORK/$FILE.class ] || javac -d $WORK $WORK/$FILE.java | |
# execute.. | |
java -cp $WORK $FILE $* | |
exit $? | |
---------- Write some Java dude! ---------- | |
public class Ick { | |
public static void main(String[] args) { | |
System.out.println("Whoo Hooo!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment