Skip to content

Instantly share code, notes, and snippets.

@lenny
Created October 24, 2011 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lenny/1309229 to your computer and use it in GitHub Desktop.
Save lenny/1309229 to your computer and use it in GitHub Desktop.
Ruby wrapper around Java Properties
# More rubyish/convenient interface to Java Properties(e.g. Loading connection config from properties file)
class JavaProperties
def initialize(name)
input_stream =
Java::Java.lang.Thread.currentThread.contextClassLoader.getResourceAsStream(name)
if input_stream
@properties = Java::java.util.Properties.new
@properties.load(input_stream)
input_stream.close
else
raise "#{name} not found in classpath"
end
end
def [](name)
@properties.getProperty(name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment