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
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 | |
} | |
} | |
} |
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
def extConfigPath = new ExtConfig().find('pathToExtFile') | |
if(extConfigPath) { | |
external.file = new File(extConfigPath) | |
if(external.file.exists()) { | |
println "Loading external config at ${external.file.path}" | |
grails.config.locations = [ "file:${external.file.path}" ] | |
} | |
else { | |
println "External config defined at ${extConfigPath} doesn't exist (huh?)" | |
} | |
} | |
else { | |
println "No external config found" | |
} |
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
<Context> | |
<Environment name="pathToExtFile" value="/path/to/external/file" type="java.lang.String" /> | |
</Context> |