4

I have a Java Spring MVC web application. I was using an application.properties file to set a few properties value. Now I am trying to get the properties independent of the war file. I have created a new folder shared/classes under tomcat as shown here.

folder

In the catalina.properties file I have added shared.loader=${catalina.base}/shared/classes.

In my root-context.xml file, I added

<context:property-placeholder location="file:${catalina.base}/shared/classes/application.properties"/>

But I am getting the following error:

ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: E:\projects\smartwcm\workspace-20163101-eclipse-wp\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\shared\classes\application.properties (The system cannot find the path specified)

How can I fix this issue?

Geo Thomas
  • 1,095
  • 2
  • 21
  • 45
  • 2
    Looks like you are using Eclipse's Tomcat to run the application, so you app is looking into Eclipse's tomcat directory. Try putting the complete physical path or deploy your app in Tomcat installation dir in which you have put the app.prop file. – Sanjay Rawat May 14 '16 at 13:06
  • @Sanjay Rawat, I want to add this property in my Eclipse's Tomcat. I dont want to put a complete physical path here – Geo Thomas May 16 '16 at 06:33
  • Yes, I understand. But Eclipse's Tomcat folder is tricky, one answer below explains that - "This is probably one of the limitations of the Servers folder created by eclipe. Where it actually places the contents of this folder is in .metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf...." That is why I suggested you to try the full physical path and then figure out where exactly Eclipse is storing that properties file in its Tomcat. – Sanjay Rawat May 16 '16 at 20:53

4 Answers4

6

This is probably one of the limitations of the Servers folder created by eclipe. Where it actually places the contents of this folder is in

.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf

I've tried this locally and eclipse doesn't seem to publish any folder I create. And eclipse is very specific in naming the folder Tomcat v8.0 Server at localhost-config. This may also imply that property and configuration files are the only accepted system files. I can make everything work very well just by putting an application.properties file at the same level as for example catalina.properties. Then I publish with eclipse and then when I look at the temporary folder, the application file is there. Anyways there doesn't seem to be a specific reason to have your file in shared/classes. After all, as far as I can tell, they are properties to be shared in the server, so I would say their rightfull place is in the config folder.

  • 1
    I got things working in the way you suggested, but I am not sure if it a good approach to add custom property files under conf. That's why I am trying to add the shard folder. – Geo Thomas May 17 '16 at 03:10
2

Check out this answear. Maybe it will help

Where to place and how to read configuration resource files in servlet based application?

Community
  • 1
  • 1
Mafick
  • 1,054
  • 1
  • 12
  • 25
1

It looks like ${catalina.base} is being interpreted as:

E:\projects\smartwcm\workspace-20163101-eclipse-wp.metadata.plugins\org.eclipse.wst.server.core\tmp0

Have you set the $CATALINA_BASE variable on the machine you're running?

Daniel Patrick
  • 2,901
  • 4
  • 21
  • 42
1

I think you need to point to ${catalina.home}. Catalina.base is where tomcat is installed, catalina.home is where tomcat is run from. (This is due to tomcat multihost environment; you can have one instalation of tomcat and multiple hosts).

When encountering problems like this, (if you're on Windows) you should use program FileMon from Sysinternals suite. You should setup a fiter: "PATH contains YOURFILE.NAME" and see search paths where the file is looked. Then you can easily figure out where java process is trying to look for a file and put it in corresponding folder.

However, it's best to setup a normal directory somewhere outside of server home/base, and reference it via absolute OS file path.

Mitja Gustin
  • 1,583
  • 12
  • 17