I've tried working on this for a couple hours and still couldn't get it right so I figured I would ask. I am trying to use log4j to write program statements to an output file and have this working on my local machine just fine.
I currently have my log4j.properties file in a folder called logging. It is marked as a source folder. When generating my runnable JAR file via eclipse, I place it on another server to run and it says the log4j.properties file cannot be found. I've tried a few different things so far and nothing is working. All I want to do is make sure the log4j.properties file is included in the runnable JAR. My setup is the following right now.
Project foler - called test
-logging\log4j.properties.
In my Java program I have the following code that is working locally. Am I missing some fundamental step during the JAR generation process in Eclipse? Seems like this should be easy but its not right now. I've even extracted the JAR in 7zip after creation and sure enough, the logging file is not there at all. Its like it has complete disappeared for some reason. I would greatly appreciate it if anyone could help me out, thank you.
public static void main(String[] args)
{
FileInputStream fis = new FileInputStream("logging\\log4j.properties");
if(fis != null)
{
PropertyConfigurator.configure(fis);
}
logger.info("process started.");
}
UPDATE
Instead of using InputStream directly, I modified my code to just use the below and it is now working, accessing the log4j.properties file through the runnable jar.
PropertyConfigurator.configure(Converter.class.getResourceAsStream("/logging/log4j.properties"));
logger.info("Conversion process started.");