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
public static void main(String args)
FileInputStream fis = new FileInputStream("logging\\log4j.properties");
if(fis != null)
logger.info("Conversion process started.");
I see 2 issues: a) when you create a jar using eclipse, by default it only zips the compiled classes (so .class files) into your target .jar file, you need to specify to eclipse that you also want to include the resources of your project, these can be config files like a properties file for log4j, but can also be resource bundles for i18n messages etc.... An explanation how to do this can be found here: Java & Eclipse: Resources in JAR?. So if the properties for log4j are not in the jar file then double check the jar file creation!
b) if you have the resources in your jar file, you cannot read them using a fileinputstream: they are not stored in a standalone file, they are stored in the jar file. I assume that your jar file is part of the classpath, so when you have achieved adding the resources into your jar file, you need to treat them as resources: see Load resource from anywhere in classpath for more info on this subject