Compile and run applet with just java file, bash script

Alec Jacobson

February 01, 2010

weblog/

I had the habit of creating little bash scripts for each java applet I worked on. These were such boilerplate, not to mention the boilerplate html for each applet. So here's a script the takes the main applet file as a parameter and compiles the code, creates some html on the fly and runs the applet:
#!/bin/bash
#
# Usage:
#   ./appletmakeandview.sh Applet.java
#

base=`echo $1 | sed "s/\.java$//g"`;
if javac -source 1.5 -target 1.5 $base.java; then
  if [ ! -e $base.html ]
  then
    echo "<applet code=$base width=600 height=600></applet>" | cat > $base.html
  fi
  appletviewer $base.html
fi