Created
December 13, 2013 18:08
-
-
Save codacoder/7948547 to your computer and use it in GitHub Desktop.
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
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