-
-
Save dcalacci/3692514 to your computer and use it in GitHub Desktop.
Simple and Easy way to run a java class.
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment