2011-05-18 125 views
0

我的代碼的一些代碼片段如下所示;類路徑錯誤

String log4jConfigPath = FileUtil.getFilePathFromClasspath("log4j.properties"); 
    if (null != log4jConfigPath) { 
     PropertyConfigurator.configureAndWatch(log4jConfigPath); 
    } else { 
     logger.warn("log4j.properties not found on classpath!"); 
    } 
    Config config = Config.getConfig("crawler.properties"); 
    String mode = config.getString("crawler.mode").toLowerCase(); 

我爲得到一個錯誤的兩個文件「log4j.properties」和「crawler.properties」不上課path..i發現有居住在此文件夾中的文件我projects..Can有人告訴我如何將此文件添加到類路徑編譯器查找這兩個屬性文件。

謝謝;

+1

這些文件在哪些文件夾中?他們應該從外觀的默認包裝中。 – 2011-05-18 05:44:10

+0

嗨我把所有的文件移動到默認包....它現在不顯示錯誤... thnks – arien 2011-05-18 06:36:14

回答

0

的文件夾,包含log4j.properties已被添加到類路徑,或者相對於當前的工作目錄或絕對:

/ 
+-project 
    +-src 
    | +-com 
    | +-example 
    | +-Hello 
    +-resource 
    +-log4j.properties 

現在,如果你的當前目錄是/project,那麼你必須運行應用程序

java -cp src;resource com.example.Hello      # relative paths 
java -cp /project/src;/project/resource com.example.Hello  # absolute paths