【发布时间】:2010-10-07 08:15:33
【问题描述】:
我在本地 Tomcat 中运行了一个 webapp。路径为:tomcat/webapps/myproject.
我在这个项目中有一些资源都在这个路径的文件夹中:tomcat/webapps/myproject/resources
所以,我正在尝试使用文件config.properties 从 Java 项目访问这些资源。在这个文件中我有这样的东西:
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");
}
我不知道出了什么问题,在我之前做的项目中,与此类似,我有类似的东西,它找到了一切。
有任何想法吗??提前致谢。
【问题讨论】:
-
好的,我重新提出我的问题。你在哪里保存你的 Java 代码?基本上你的 webapp 的文件夹结构是什么。
-
我想做的项目,只是为我的webapp项目提供服务。但是真的很没意思吗??我的意思是,我在 config.properties 中连接到我的本地主机,对吗?感谢您的评论和回答
标签: java tomcat configuration path