从java中的包加载log4j属性

Har*_*sha 9 java properties log4

在我的java swing应用程序中,我从存储在应用程序包中的属性文件中加载log4j属性,并将该属性文件加载为,

try {                            
     PropertyConfigurator.configure("conf/log4j.properties");
     logger.info("Starting the system.");                           

} catch (Exception e) {
     e.printStackTrace();

}
Run Code Online (Sandbox Code Playgroud)

然后我在应用程序启动时出现以下错误,

log4j:ERROR Could not read configuration file [conf/log4j.properties].
java.io.FileNotFoundException: conf/log4j.properties (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at java.io.FileInputStream.<init>(FileInputStream.java:97)
        at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:297)
        at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:315)
        at com.bio.ofm.mnu.views.SplashScreen$1.run(SplashScreen.java:70)
        at java.lang.Thread.run(Thread.java:722)
log4j:ERROR Ignoring configuration file [conf/log4j.properties].
log4j:WARN No appenders could be found for logger (com.bio.ofm.mnu.views.SplashScreen).
log4j:WARN Please initialize the log4j system properly.
Run Code Online (Sandbox Code Playgroud)

这种加载属性文件的方式是错误的吗?请帮忙.

我构建一个.jar文件并使用该jar运行应用程序**

Die*_*o D 18

如果conf是您可以使用的源文件夹:

PropertyConfigurator.configure("classpath:conf/log4j.properties");
Run Code Online (Sandbox Code Playgroud)

否则你可以试试这个:

PropertyConfigurator.configure(this.getClass().getClassLoader().getResource("conf/log4j.properties"));
Run Code Online (Sandbox Code Playgroud)