Reputation: 3563
I have a webapp running in my local Tomcat. The path is: tomcat/webapps/myproject
.
I have some resources in this project all in a folder with this path: tomcat/webapps/myproject/resources
So, I am trying to acces to this resources from a Java project, using a file config.properties
. In this file I have something like this:
tomcat.url= http://localhost
tomcat.port=8080
tomcat.resources=/myproject/resources
I tryed also different combinations of /
or \
but I get this error running my project:
Trying to acces to a directory that does not exist
My Java code:
Configuration config = new PropertiesConfiguration("config.properties");
String sourcePath = config.getString("tomcat.resources");
//And I try to list this folder
File dir = new File(sourcePath);
String[] children = dir.list();
if (children == null) {
// Either dir does not exist or is not a directory
throw new ServiceExecutionException("Trying to generate Metadata in a directory that does not exist");
}
I don't know what is wrong, in projects I made before, simliar to this, I had something similar and it found everything.
Any ideas?? Thanks in advance.
Upvotes: 0
Views: 1018
Reputation: 11497
the file must be located at Check update.tomcat/webapps/myproject/src/main/resources
I don't know how you are accessing the file, but just in case I'd recommend you to use PropertiesConfiguration
private static final String CONFIGURATION_PATH = "config.properties";
PropertiesConfiguration configuration = new PropertiesConfiguration(CONFIGURATION_PATH);
Edited
The problem is that you are trying to open a file located (keeping in mind that "/" is your root file system) at /myproject/resources
when your file is located at (probably) /var/lib/tomcat6/webapps/myproject/resources
.
You can get the real path of your file using ServletContext#getRealPath
Upvotes: 1