我有一个webapp在我的本地Tomcat中运行。路径是:tomcat/webapps/myproject
。
我都在这个路径中的文件夹,在这个项目中的一些资源:tomcat/webapps/myproject/resources
从Java访问Tomcat路径
所以,我从一个Java项目试图查看在此资源,使用文件config.properties
。在这个文件中我有这样的事情:
tomcat.url= http://localhost
tomcat.port=8080
tomcat.resources=/myproject/resources
我tryed也有不同的/
或\
组合,但我得到这个错误运行我的项目:
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");
}
我不知道什么是错的,在我之前制作的项目中,似乎是这样,我有类似的东西,它找到了一切。
任何想法??提前致谢。
好你的文件的真实路径,我改一下我的问题。你在哪里保存你的Java代码?基本上什么是你的web应用程序的文件夹结构。 – pakore 2010-10-07 09:17:04
我想要这样做的项目只是为我的webapp项目提供服务。但它真的是啥?我的意思是,我在config.properties中连接到本地主机,对吗?感谢您的commnents和答案 – 2010-10-07 09:24:33
检查我的更新。 – pakore 2010-10-07 09:46:10