Заменить заполнители переменных среды их фактическим значением?JAVA

Программисты JAVA общаются здесь
Anonymous
Заменить заполнители переменных среды их фактическим значением?

Сообщение Anonymous »

В моем файле Application.properties я использую такой ключ и значение

report.custom.templates.path=${CATALINA_HOME}\\\\Medic\\\\src\\\\main\\\\reports\\\\AllReports\\\\


Мне нужно заменить ${CATALINA_HOME} с его фактическим путем:

Код: Выделить всё

{CATALINA_HOME} = C:\Users\s57893\softwares\apache-tomcat-7.0.27
Вот мой код:

Код: Выделить всё

public class ReadEnvironmentVar {

public static void main(String args[]) {

String path = getConfigBundle().getString("report.custom.templates.path");
System.out.println("Application Resources : " + path);
String actualPath = resolveEnvVars(path);
System.out.println("Actual Path : " + actualPath);

}

private static ResourceBundle getConfigBundle() {
return ResourceBundle.getBundle("medicweb");
}

private static String resolveEnvVars(String input) {
if (null == input) {
return null;
}

Pattern p = Pattern.compile("\\$\\{(\\w+)\\}|\\$(\\w+)");
Matcher m = p.matcher(input);
StringBuffer sb = new StringBuffer();
while (m.find()) {
String envVarName = null == m.group(1) ? m.group(2) : m.group(1);
String envVarValue = System.getenv(envVarName);
m.appendReplacement(sb, null == envVarValue ? "" : envVarValue);
}
m.appendTail(sb);
return sb.toString();
}
}
из моего кода я получаю результат как -

Фактический путь:

Код: Выделить всё

 C:Userss57893softwaresapache-tomcat-7.0.27\Medic\src\main\reports\AllReports\
но мне нужен результат как -

Фактический путь:

Код: Выделить всё

C:\Users\s57893\softwares\apache-tomcat-7.0.27\Medic\src\main\reports\AllReports\
Пришлите мне, пожалуйста, один пример?

Подробнее здесь: https://stackoverflow.com/questions/263 ... tual-value

Вернуться в «JAVA»