0

Firstly, I set PATH variable CATALINA_HOME=/opt/tomcat then I check it in terminal cd $CATALINA_HOME it's works.
Secondly, I created file.properties and wrote catalina.home=%CATALINA_HOME%.
Lastly, I tried to run following code


@Autowired Enviroment enviroment;
String path = environment.getProperty("catalina.home") + File.separator + "webapps" + File.separator + "templates" + File.separator;
File dir = new File(path);
but that doesn't work
 
Caused by: java.io.FileNotFoundException: %CATALINA_HOME%/webapps/templates does not exist.
    at freemarker.cache.FileTemplateLoader$1.run(FileTemplateLoader.java:124)
    at java.security.AccessController.doPrivileged(Native Method)
    at freemarker.cache.FileTemplateLoader.(FileTemplateLoader.java:121)
    at freemarker.cache.FileTemplateLoader.(FileTemplateLoader.java:107)
    at freemarker.template.Configuration.setDirectoryForTemplateLoading(Configuration.java:439)
Haygo
  • 125
  • 2
  • 12
  • what is `file.properties`, why do you think every property of this file will be set as system property ? – jmj Jul 09 '14 at 18:29
  • @JigarJoshi, I do not I have not worked with this type of file, in error message we see `%CATALINA_HOME%/` does it mean what was not recognize that strig? – Haygo Jul 09 '14 at 18:37

1 Answers1

0

If you want to get the value of the environment variable CATALINA_HOME in Java, use System.getenv("CATALINA_HOME").

I'm not sure what gives you the idea that a .properties file will make any use of environment variable values. It does not do this at all. If you have set catalina.home=%CATALINA_HOME% in your properties file, then the value you get back from the property catalina.home will always be the string %CATALINA_HOME%. Also, the File class will pay no attention at all to environment variable values. In your case, %CATALINA_HOME%/webapps/templates does not exist because there is (almost certainly) no subdirectory in Tomcat's current working directory with the name %CATALINA_HOME%.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104