Java 类路径错误
我的一些代码片段如下所示Java 类路径错误,java,Java,我的一些代码片段如下所示 String log4jConfigPath = FileUtil.getFilePathFromClasspath("log4j.properties"); if (null != log4jConfigPath) { PropertyConfigurator.configureAndWatch(log4jConfigPath); } else { logger.warn("log4j.properties no
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”时出错。我的项目中的文件夹中有这些文件。有人能告诉我如何将这些文件添加到类路径编译器查找这两个属性文件吗
谢谢, 必须将包含
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
这些文件在哪些文件夹中?从外观上看,它们应该在默认包中。嗨,我将所有文件移到了默认包中…现在没有显示错误…谢谢