Skip to content

Instantly share code, notes, and snippets.

@javierarilos
Created September 21, 2012 16:43
Show Gist options
  • Save javierarilos/3762558 to your computer and use it in GitHub Desktop.
Save javierarilos/3762558 to your computer and use it in GitHub Desktop.
Scripting in java... edit your java class and execute it directly as a shell script.
#!/bin/bash
# "Scripting" java. Download jar dependencies if needed.
# execute it directly from command line: bash < <(curl -L -k https://raw.github.com/gist/3762558/b941980bf5cf6671c3ff1477982ce370015a8333/scripting.java.sh)
if [ ! -f junit-4.11-SNAPSHOT-20120805-1225.jar ];
then
wget --no-check-certificate https://github.com/downloads/KentBeck/junit/junit-4.11-SNAPSHOT-20120805-1225.jar
fi
cat <<-EOF > Scripting.java
public class Scripting {
public static void main(String[] args){
System.out.println(" Hello \"Scripting\" java world.");
}
}
EOF
if [ ! -f Scripting.class ];
then
javac -classpath junit-4.11-SNAPSHOT-20120805-1225.jar Scripting.java
fi
time java -classpath .:junit-4.11-SNAPSHOT-20120805-1225.jar Scripting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment