Skip to content

Instantly share code, notes, and snippets.

@codacoder
Created December 13, 2013 18:08
Show Gist options
  • Save codacoder/7948547 to your computer and use it in GitHub Desktop.
Save codacoder/7948547 to your computer and use it in GitHub Desktop.
import javax.naming.Context
import javax.naming.InitialContext
import javax.naming.NamingException
class ExtConfig {
public ExtConfig() {
}
public String find(String key) {
String path = findJndiEnvVar(key)
if(!path) {
path = System.getenv(key)
if(!path) {
path = System.getProperty(key)
}
}
return path
}
private String findJndiEnvVar(String key) {
try {
def ctx = (Context) new InitialContext().lookup('java:comp/env')
return ctx.lookup(key)
}
catch(NamingException e) {
// not found, carry on
return null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment