title: Forcing work directory when executing jar file in systemd
body: <p>I am attempting to start a jar from a systemd service, in linux. The jar that I am executing assumes that within the current directory, there is an xml file. I am passing the name of that file, with the -config argument. The sample service I have created is below:</p>
  
  <p><code>[Unit]
  Description=my service
  After=network.target</code></p>
  
  <p><code>[Service]
  Type=simple
  Environment="xml_file_name=sample.xml"
  ExecStart=/usr/bin/java -jar /path/to/jar/myapp.jar -config ${xml_file_name}</code></p>
  
  <p>The service file above is placed in the /usr/lib/systemd/system directory, and is called myservice.service. I am doing the following commands to start it:</p>
  
  <p><code>systemctl daemon-reload
   systemctl stop myservice.service
   systemctl start myservice.service
   systemctl status myservice.service</code></p>
  
  <p>The <code>systemctl status myservice.service</code> command shows that the jar file ran, but my application says that it cannot find ${xml_file_name}. </p>
  
  <p>In addition, my jar states that it was executed from the / directory. I believe that this is part of the problem, because the ${xml_file_name} is only applicable in the /path/to/jar/ directory.</p>
  
  <p>Things tried:</p>
  
  <ul>
  <li><p><code>-Xbootclasspath/p:"/path/to/jar/"</code>: prepend the path of the jars
  location, so that maybe the ${xml_file_name} can be seen.</p></li>
  <li><p>changed the /path/to/jar/ to make sure it has all possible permissions enabled</p></li>
  <li><p>I tried to add <code>User=root</code> under the <code>[Service]</code> section of my systemd service, but it made no change. Either way, only root user is on the machine, and the permissions all seem to check out.</p></li>
  </ul>
  
  <p>What makes this even more strange is that if I cd to / , and then manually execute: </p>
  
  <p><code>/usr/bin/java -jar /path/to/jar/myapp.jar -config sample.xml</code></p>
  
  <p>everything words just fine.</p>
  
  <p>Is there something evident that I am missing here? Is it possible to tell systemd service, execute this java jar, but make sure that the working path is <code>/path/to/jar/</code> as opposed to <code>/</code> ?</p>