I created a backup program. Program is running great but the logs are not generating. I am generating logs using three methods ,
System.out.println(message);
try {
if(logFileWriter != null){
logFileWriter.write(message);
logFileWriter.newLine();
logFileWriter.flush();
}
Runtime.getRuntime().exec("echo " + message);
} catch (IOException e1) {}
Log file initializer:
private static void initLog() {
File logFileObj = new File(logFile);
try {
FileWriter fileWriter = new FileWriter(logFileObj);
logFileWriter = new BufferedWriter(fileWriter);
} catch (IOException e) {
e.printStackTrace();
}
}
Here message is the message that I want to log. The file writer is initiated by the log file path given by the user at the run time using the command line argument.
When i am trying to run the program using the eclipse, logs are creating but when i run the executable jar file, no logs are creating. What can be the reason.
Assumption: You are on Windows and you are creating this executable jar from Eclipse.
Not sure how your complete code looks like this is what I did based on your code:
Then project->right click->export->Runnable Jar -> Select JustPrint in the launch configuration and give the file location – > Finish
Then open command prompt browse where jar file was created, then type this command
(Considering Java path is set and I gave my jar name as exectest.jar, I can see log file being created in the same directory where jar file is located also, on my command prompt I can stacktrace while creating process.
Now with this can you trace your code and see if you do something like this or different, post your findings.