I\'m using Gradle\'s Application plugin to generate the install for a standalone java application. I have a configuration file I need to put on the classpath but I can\'t seem t
I did a variant of Martin Dow's recipe below:
I replace 'APP_HOME=' with 'export APP_HOME=' in the start script.
Then my code can do System.env.get("APP_HOME") and then navigate to e.g. the conf/ folder.
This is my Gradle hack:
tasks.startScripts {
doLast {
def scriptFile = file "${outputDir}/${applicationName}"
scriptFile.text = scriptFile.text.replaceAll('APP_HOME=', 'export APP_HOME=')
}
}
Example of Java code in the app:
String APP_HOME = System.env().get("APP_HOME");
Properties p = new Properties();
p.load(new FileInputStream(APP_HOME + "/conf/myapp.properties"))
Hope this helps.
NOTE: "export" does not work in Windows!