I’m calling a method using reflection. To do this, at runtime, I:
1) Load the JAR file containing the class that declares the method
loader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class urlClass = URLClassLoader.class;
Method method = urlClass.getDeclaredMethod("addURL", new Class[]{URL.class});
method.setAccessible(true);
method.invoke(lLoader, new Object[] {lJarFile.toURI().toURL()});
2) Call the method
lExternalMethod.invoke(lClass.newInstance());
3) The method call works and does what its supposed to do, but I get the following in the console:
log4j:WARN No appenders could be found for logger (JarName)
log4j:WARN Please initialize the log4j system properly
I don’t use log4j in my application, but the JAR I’m loading to call the method does. The method I call has multiple lines:
Logger.GetLogger().Log("Msg", "Msg description");
Also, the JAR also contains the log4j.properties file.
Is there any way to fix this issue?
Provide a Log4J configuration file, or just ignore it–it’s a harmless warning saying there’s no Log4J configuration file. (Yes, there is, but apparently not one that defines the root appenders etc.) You should only see that message on startup.