2013-03-21 56 views
0

以下配置工作时,我在本地机器上部署WEP的应用程序(窗口)Log4j配置在JSF的Web应用程序

public void contextInitialized(ServletContextEvent sce) { 
    Logger logger = null; 
    ServletContext servletContext = sce.getServletContext(); 
    String prefix = servletContext.getRealPath("/"); 
    String log4jFile = servletContext.getInitParameter("log4j");  
    if (log4jFile != null) { 
     DOMConfigurator.configure(prefix + log4jFile); 
     logger = LogManager.getLogger(StartupListener.class.getName()); 
     logger.info("LOG4J loaded successfully: " + log4jFile); 
    } 
} 

<context-param> 
    <param-name>log4j</param-name> 
    <param-value>WEB-INF/classes/com/domain/resources/log4j.xml</param-value> 
</context-param> 
<listener> 
    <listener-class>com.domain.util.StartupListener</listener-class> 
</listener> 

但在Linux中安装Web应用程序时,我得到了以下错误信息:

log4j:ERROR Could not parse file [nullWEB-INF/classes/com/domain/resources/log4j.xml]. 
java.io.FileNotFoundException: /app/home/wdmt3/AdminServer/nullWEB-INF/classes/com/domain/resources/log4j.xml (No such file or directory) 

有什么建议吗?

回答

0

通过配置适当weblogic的问题解决服务器以检索路径(域 - > Web应用程序 - >存档的实际路径启用)

0
<context-param> 
    <param-name>log4j</param-name> 
    <param-value>/WEB-INF/classes/com/domain/resources/log4j.xml</param-value> 
</context-param> 
0

问题

  • 的ServletContext.getRealPath返回NULL,你日志文件路径成为

    nullWEB-INF/classes/com/domain/resources/log4j.xml 
    

这是不可能的加载该文件,并log4j的只是会引发您看到的错误消息。

  • 那么为什么servletContext.getRealPath返回null?

ServletContext.getRealPath(String path)状态的API文档:

如果servlet容器无法给定的虚拟路径转换成一个真正的路径此方法返回null。

不同的容器可能具有完全不同的行为。

解决方案

  • 从Spring MVC的与solution试并确保log4jFile开始以 '/':

    String log4jFile = servletContext.getInitParameter("log4j"); 
    String fullPath = servletContext.getRealPath(log4jFile); 
    
+0

我不使用spring,基本上唯一有效的选择是在weblogic中将服务器日志记录选项更改为log4j – angus 2013-03-21 13:30:46

+0

您是否尝试过解决方案中的代码?实际上你不需要使用弹簧。 – 2013-03-21 15:01:35

+0

你是什么意思“log4jFile以'/'开头? – angus 2013-03-21 15:21:33