我有一個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