Skip to content

Instantly share code, notes, and snippets.

@automatthew
Created November 10, 2009 20:13
Show Gist options
  • Save automatthew/231231 to your computer and use it in GitHub Desktop.
Save automatthew/231231 to your computer and use it in GitHub Desktop.
compile and run trivial Java with Rake
# instant.rake
# Rake rules for compiling and running trivial Java programs
#
# Usage: rake com.example.MonkeyShines
# Source goes under ./src
# Classes end up under ./target
require 'rake/clean'
libs = FileList["lib/*"]
libs << "target"
JavaClassPaths = libs.join(":")
# regex should weed out anything containing "/", i.e. paths
rule(/^[^\/]+\.\w/ => lambda {|tn| "src/#{tn.gsub(".", "/")}.class"} ) do |t|
puts command = "java -classpath #{JavaClassPaths} #{t.name}"
system(command)
end
rule ".class" => [".java", "target"] do |t|
puts command = "javac -classpath #{JavaClassPaths} #{t.source} -d target"
system(command)
end
desc "make directories, or whatever"
task :setup => ["src", "lib"]
directory "target"
directory "src"
directory "lib"
CLEAN.include("target")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment