Skip to content

Instantly share code, notes, and snippets.

@lenny
Created January 9, 2012 15:51
Show Gist options
  • Save lenny/1583527 to your computer and use it in GitHub Desktop.
Save lenny/1583527 to your computer and use it in GitHub Desktop.
Java Classpath Helper
class JavaClasspath
class << self
def bootstrap(jar_dirs, classpath_dirs)
jar_dirs.each do |jardir|
Dir.entries(jardir).grep(/\.jar$/) {|jar| add_expanded_path(File.join(jardir, jar))}
end
classpath_dirs.each do |cp_dir|
add_expanded_path(cp_dir)
end
end
def add_expanded_path(file)
if File.directory?(file)
$CLASSPATH << "#{File.expand_path(file)}/"
else
$CLASSPATH << File.expand_path(file)
end
end
def add_jars_from_dir(jardir)
unless File.exists?(jardir)
raise "#{jardir} doesn't exist"
end
Dir.entries(jardir).grep(/\.jar$/) {|jar| add_expanded_path(File.join(jardir, jar))}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment