Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
Created September 10, 2012 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nixpulvis/3689036 to your computer and use it in GitHub Desktop.
Save nixpulvis/3689036 to your computer and use it in GitHub Desktop.
Simple and Easy way to run a java class.
#!/usr/bin/env ruby
# ## An Easy Way to Compile and Run Java Classes
#
# System utility for compiling and running Java classes
# in a specific directory structure.
#
# #### Recommended Installation
# Save this code to a file named `easyjava`, somewhere on your HD. Then
# in your `~/.bash_profile` add the following:
#
# alias easyjava="/path/to/easyjava"
#
# #### Directory structure
# The bin folder will be automatically created if you don't have one.
#
# project/
# |
# |- src/
# |- bin/
#
# #### Usage
# It is required that you be executing this script from the projects directory.
#
# easyjava AClass
#
require 'optparse'
# All of the options parsed from the commandline.
options = {}
optparse = OptionParser.new do |opts|
# Help banner
opts.banner = "Usage: easyjava [options] class"
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
optparse.parse!
unless ARGV.size == 1
puts optparse.help
exit
end
# Ensure we have a src folder, quit if not.
unless File.directory? 'src'
puts "No src directory found."
exit
end
# Ensure we have a bin folder, make one if not.
Dir.mkdir "bin" unless File.directory? 'bin'
# The class we want to run.
klass = ARGV[0]
compile = system "javac -d bin src/*.java"
system "java -cp bin #{klass}" if compile
@nixpulvis
Copy link
Author

This needs to be able to handle multiple files and libs.

@nixpulvis
Copy link
Author

Handles all files in src now. Still want to add external lib support.

@nixpulvis
Copy link
Author

this has been made into a ruby gem, located here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment