类路径错误

时间:2011-05-18 05:36:56

标签: java

我的代码的一些代码段如下所示;

    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”这两个文件的错误..我的项目文件夹中有这些文件。有人请告诉我如何添加这个文件到类路径编译器会查找这两个属性文件。

感谢;

1 个答案:

答案 0 :(得分: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