我有一个使用log4j的Eclipse Java项目。我无法设置log4j配置文件被文件路径访问。我必须在jar中导出和运行项目。如何设置log4j属性文件?
这里是我想:
public class Wita {
static Logger logger;
public static void main(String[] args) {
System.setProperty("log4j.configuration", new File("").getCanonicalPath()+File.separatorChar+"resources"+File.separatorChar+"log4j.xml");
// System.out.println(System.getProperty("log4j.configuration"));
logger = Logger.getLogger(Wita.class.getName());
}
}
系统进行打印C:\用户\ roncsak \ eclipse_workspace \ WITA \资源\的log4j.xml这是很好的。 WITA是该项目的基础文件夹。但随着-Dlog4j.debug参数运行项目的下列回报也:
log4j: Trying to find [C:\Users\roncsak\eclipse_workspace\WITA\resources\log4j.xml] using context classloader [email protected] log4j: Trying to find [C:\Users\roncsak\eclipse_workspace\WITA\resources\log4j.xml] using [email protected] class loader. log4j: Trying to find [C:\Users\roncsak\eclipse_workspace\WITA\resources\log4j.xml] using ClassLoader.getSystemResource(). log4j: Could not find resource: [C:\Users\roncsak\eclipse_workspace\WITA\resources\log4j.xml].
我想改变的log4j.xml随着时间的推移,无需另建jar文件。我怎样才能做到这一点?
它的工作原理!非常感谢你! – roncsak
'java.io.File.toURL()'现在已经过时。相反,使用:'x.toURI()。toURL()' – kevinarpe
它的功能完美,只是一个“文件:”花了我一整个早上,我想亲吻你的家伙。 – BenBen