For 4, you could try this. Get the classpath:
String classpath = System.getProperty("java.class.path");
Then search it for the name of your application jar:
int jarPos = classpath.indexOf("application.jar");
Parse out the path leading up to it:
int jarPathPos = classpath.lastIndexOf(File.pathSeparatorChar, jarPos) + 1;
String path = classpath.substring(jarPathPos, jarPos);
Then append MyApp.properties
. Make sure to check for jarPos == -1
, meaning the jar isn't found if the classpath (perhaps when running in your dev environment).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…