Resource files not picked up from WEB-INF/classes/ folder
Hi,
I am using Eclipse and IntelliJ side by side, on the same project.
I have configured my web app with Tomcat.
The web application is deployed within the project directory here:
{PROJECT_DIR}\classes\artifacts\opencv_web_war_exploded
When I attempt to run the web app, I get a NPE for the database properties file:
=======================
java.io.FileNotFoundException: C:\Apps\apache-tomcat-7.0.79\bin\db.properties (The system cannot find the file specified)
..
..
..
user.dir=C:\Apps\apache-tomcat-7.0.79\bin
C:\Apps\apache-tomcat-7.0.79\bin\res\db.properties --> Exists=false
Loading: C:\Apps\apache-tomcat-7.0.79\bin\db.properties
=======================
As you see I am printing the user.dir property and I see that it is pointing to Tomcat bin directory and looking for db.properties file over there.
Also, the properties file is in a resources folder which is marked as "Resources Root" and the file is exploded to under WEB-INF\classes\ as expected and as shown below:
{PROJECT_DIR}\classes\artifacts\opencv_web_war_exploded\WEB-INF\classes\db.properties
Question:
1. Why is the resource file not picked up from WEB-INF\classes\?
2. Why is the user.dir property pointing to Tomcat bin directory?
How to resolve this issue
Please sign in to leave a comment.
What code do you use to load the resource? You should load it from the classpath.
Using new ClassPathXmlApplicationContext("META-INF/ignite-config-common-client.xml");
How does this code find db.properties file?
The db.properties file is in the resources folder. So eclipse copies it to WEB-INF/classes/db.properties under the server deployment folder.
Also I can get Eclipse's deployment folder using:
System.getProperty("wtp.deploy");
is there anything similar with Intellij?
Should be able to run the project on both Eclipse and Intellij
IntelliJ IDEA should do the same, check the artifact output directory and the configuration. https://www.jetbrains.com/help/idea/artifacts.html.
It's still not clear how your code is searching for this file. Share the sample project if you need further assistance.