是否应该在..\TestLogProj\TestLogWebApp\WEB-INF\classes下面?

解决方案 »

  1.   

    1.看看打包的时候真的打进去没有,2.说实话,我没用过这样方式的初始化,但我想应该是只要包含在classpath里就可以了的。楼主可以试试用properties文件来进行初始化的定义,只要把这个文件放到classpath里面(或者说classpath包含)就可以了,而且用起来也比较方便。而且除了classpath外,weblogic也不需要其它的设置。这里有个网址
    http://www.jfsys.com/jfsys_web/main/service/service_log4j.htm
    楼主不妨看看:)
      

  2.   

    应该是全路径.并且,我认为,log4j配置不成功,不应该引起系统启动不起来。因为还有默认配置的。给你看看我的初始化程序:
    import java.io.File;import org.apache.log4j.Logger;
    import org.apache.log4j.BasicConfigurator;
    import org.apache.log4j.xml.DOMConfigurator;
    public class LogUtil {  public LogUtil() {
      }  /**
       * init Log4J by XML file
       * @param logConfFile
       */
      public static void initLogByXML(String logConfFile)
      {    try {
          System.out.println("---------------- Log4J init,please waitting.....");
          if (logConfFile == null || logConfFile.equals("")) {
            BasicConfigurator.configure();
            throw new IllegalArgumentException("Log4J ConfigFile not input!");
          }
          File file = new File(logConfFile);
          if (!file.exists()) {
            BasicConfigurator.configure();
            throw new IllegalArgumentException("Log4J ConfigFile not find!");
          }      System.out.println("try config by XML file: " + logConfFile);
          DOMConfigurator.configure(logConfFile);
        }
        catch (Exception e) {
          System.out.println("Log4J Config by XML Unseccessful!");
          BasicConfigurator.configure();
        }
        System.out.println(
            "---------------Log4J Config successful-----------------");  }}
      

  3.   

    谢谢大家,我只是找到了属性文件即 ***.properties文件的读取方法。
    当文件打到war包以后读取的方式就要产生变化,
    getServletContext().getRealPath("/") 也无法得到路径。
    必须以流的形式读入。但是我依然没有找到,怎么读取xml文件的方式,不知道各位大侠是否可以告诉我。