我有一个在本地Tomcat中运行的webapp。路径是:tomcat/webapps/myproject。
我在这个项目中有一些资源,都在以下路径的文件夹中:tomcat/webapps/myproject/resources
因此,我正在尝试使用file来访问Java项目中的这些资源config.properties。在这个文件中,我有这样的东西:
tomcat.url= http://localhost
tomcat.port=8080
tomcat.resources=/myproject/resources
我也尝试了/或的不同组合,\但在运行项目时遇到此错误:
Trying to acces to a directory that does not exist
我的Java代码:
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");
}
我不知道出什么问题了,在我之前做过的项目中,与此类似,我有类似的东西,它找到了一切。
有任何想法吗??提前致谢。