无法将netbeans指向我的log4j.xml文件

时间:2013-06-19 13:31:26

标签: classpath java-ee-6 netbeans-7 slf4j log4j2

我有一个webbapp,我正在使用SLF4J和Log4j。一切正常,除了记录机制: 当我尝试使用

DOMConfigurator.configure("log4j.xml");

我明白了  java.io.FileNotFoundException: C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.34\bin\log4j.xml (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:120) at java.io.FileInputStream.<init>(FileInputStream.java:79) at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70) at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161) at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:651) at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:772) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:232) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208) at org.apache.log4j.xml.DOMConfigurator$1.parse(DOMConfigurator.java:749) at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:871) at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:755) at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.java:896) at com.dataart.mediaportal.servlet.LoginServlet.service(LoginServlet.java:37) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)

但是当我把log4j.xml文件放在tomcat / bin目录中时 - 一切都很完美。 如何将我的IDE或项目(dunno究竟指向错误)指向项目的根目录而不是tomcat / bin?

我感谢每一个答案。感谢。

1 个答案:

答案 0 :(得分:0)

解决方案: 只需将log4j.xml放在/ resources /的根目录中,然后将以下行应用到pom.xml

<src.main.dir>src/main</src.main.dir>
<main.resources.dir>${src.main.dir}/resources</main.resources.dir>