title: Jar file ran by cron doesn't write his own log
body: <p>I have a simple java program (Java version 1.7), which is an email sender, and I want to log some events during its running. So I decided to use <code>org.apache.log4j.Logger</code> for this. I created the log4j.properties file which contains the following:</p>
  
  <pre><code>log4j.rootLogger=INFO, file
  log4j.appender.file=org.apache.log4j.RollingFileAppender
  log4j.appender.file.File=Autoemail.log
  log4j.appender.file.MaxFileSize=2MB
  log4j.appender.file.MaxBackupIndex=10
  log4j.appender.file.layout=org.apache.log4j.PatternLayout
  log4j.appender.file.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss,SSS} %5p %c{1}:%L - %m%n
  log4j.appender.file.encoding=UTF-8
  </code></pre>
  
  <p>This is how I load the configuration:</p>
  
  <pre><code>PropertyConfigurator.configure(cl.getResource("resources/log4j.properties"));
  logger = Logger.getLogger("");
  logger.info("Auto email sending started...");
  </code></pre>
  
  <p>where cl is the classloader. When I run this from Eclipse on my localhost, everything works as desired, the log file has been created if didn't exist, and on next run it is appended.</p>
  
  <p>Then I wanted to run this email sender program automatically every day at 7 am. I created the scheduled cron job, which executes the following:</p>
  
  <pre><code>java -jar /var/projects/Autoemail/Autoemail.jar  2&gt;&gt; /var/projects/Autoemail/Autoemail.err
  </code></pre>
  
  <p>On first run it worked fine, the log file had been created and info or error had been inserted, but since then the program doesn't write any event into it. The jar file runs, because I can see the sent emails. When I started searching for the reason, and ran the command, it showed me a <code>Permission denied</code> error. I checked the rights of the log file, and it was: <code>rw-rw-r--</code>. So I modified, at last to <code>rwxrwxrwx</code>, but still doesn't write the log, and I can't see any error message in the syslog file. The owner doesn't need sudo right, I think. BTW the server is Ubuntu 13/04.</p>
  
  <p>Does anyone have any idea of what can be wrong, what is still needed, or what do I have to do?</p>