-
-
Save kares/d78d138165da7ad225b6 to your computer and use it in GitHub Desktop.
This file contains 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
if RUBY_PLATFORM == "java" | |
require 'java' | |
module JndiProperties | |
java_import javax.naming.InitialContext | |
def self.getProperty(name) | |
begin | |
env.lookup(name).to_s | |
rescue | |
nil | |
end | |
end | |
def self.[](name) | |
getProperty(name) | |
end | |
private | |
def self.env | |
context = InitialContext.new | |
puts "initial context = #{context}" | |
environment = context.lookup 'java:comp/env' | |
environment | |
end | |
end | |
else | |
module JndiProperties | |
def self.getProperty(name) | |
nil | |
end | |
def self.[](name) | |
getProperty(name) | |
end | |
end | |
end | |
puts JndiProperties['ANTARCTICLE_DB_USER'].inspect | |
# output from jruby initial_context.rb : | |
# $ initial context = javax.naming.InitialContext@9d2f333 | |
# $ nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment