2013-03-21 57 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