title: Environment variables in Ubuntu Tomcat, Apache and Java
body: <p>I have a java web app running in Windows enviroment and I want to move it to Ubuntu system.
  In windows I use an environment variable to store the main path:</p>
  
  <pre><code>MAIN_PATH=C:\test
  </code></pre>
  
  <p>This variable is used in many configuration files and  also by application, for example:</p>
  
  <ul>
  <li>Apache and Tomcat configuration file</li>
  <li>Application logging configuration (log4j)</li>
  <li>Java application itself by System.getEnv(...)</li>
  </ul>
  
  <p><strong>examples:</strong></p>
  
  <p>tomcat config</p>
  
  <pre><code> &lt;Host name="localhost"  appBase="${MAIN_PATH}/webapps" unpackWARs="true" autoDeploy="true"&gt;
  </code></pre>
  
  <p>apache virtualhost</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      DocumentRoot "${MAIN_PATH}/www"
      ServerName testmain
      &lt;Directory "${MAIN_PATH}/www"&gt;
  ...
  </code></pre>
  
  <p>I can not find some way to set it in ubuntu, I tried this places:</p>
  
  <pre><code>/etc/enviroment
  /etc/profile
  </code></pre>
  
  <p><code>export MAIN_PATH=/opt/test</code> in /etc/init.d/tomcat7.sh</p>
  
  <p>All this solution didn't work or works just in one of my requirements (only in server configuration but not in application or vice versa).</p>
  
  <p>Is nothing like windows global environment variable to use for all this cases?</p>