Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Like it's described <a href="https://serverfault.com/questions/16355/how-to-set-global-path-on-os-x/277034#277034">here for OS X 10.8</a> and <a href="http://overwatering.org/blog/2012/08/setting-path-osx-mountain-lion/" rel="nofollow noreferrer">here for OS X 10.7</a> the only complete solution is to set your <code>PATH</code> in <code>/etc/launchd.conf</code>.</p> <p>Per default the <code>PATH</code> for Applications ist set to <code>/usr/bin:/bin:/usr/sbin:/sbin</code>, even if you do <em>not</em> have a <code>/etc/launchd.conf</code> at all.</p> <p>So you have to do the following in your terminal:</p> <pre><code>sudo vi /etc/launchd.conf </code></pre> <p>and add the following line or modify it, if it already exists:</p> <pre><code>setenv PATH /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin </code></pre> <p><strong>Important:</strong> Now you <strong>need</strong> to reboot your Mac!</p> <p>You can reproduce your <code>PATH</code> in your Java application with the following code:</p> <pre><code>public class Main { public static void main (String[] args) { System.out.println("PATH=" + System.getenv().get("PATH")); } } </code></pre> <p>There is a second solution, if you start your Program from within an IDE like Eclipse you can set the PATH there as well. In Eclipse you can do that via <code>Run | Run Configurations | Environment</code> while selecting your launch configuration on the left side bar under <code>Java Application</code>.</p> <p>I did reproduce it with the following code and <code>image.jpg</code> located in <code>${user.dir}</code> aka the current directory where your Java app got launched from.</p> <pre><code>import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { public static void main (String[] args) { System.out.println("PATH=" + System.getenv().get("PATH")); try { Process exec = Runtime.getRuntime().exec("identify image.jpg"); InputStream is = exec.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); System.out.println(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } } </code></pre> <p>You should get similar output like this after running the code above:</p> <pre><code>PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin image.jpg JPEG 690x518 690x518+0+0 8-bit sRGB 152KB 0.000u 0:00.000 </code></pre> <p>The first output line show your <code>PATH</code> for the Java application you run right now. The second output line comes from <code>identify image.jpg</code>.</p> <p>Note: I am running Mac OS X 10.8.2 and MacPorts 2.1.3</p> <hr> <p>Note: There were a way prior to Mac OS X 10.8 to set global variables on a user by user base employing <code>~/.MacOSX/environment.plist</code>. But this is no longer working anymore starting with Mountain Lion (aka Mac OS X 10.8). Details can be checked out here: </p> <ul> <li><a href="https://apple.stackexchange.com/questions/57385/where-are-system-environment-variables-set-in-mountain-lion">https://apple.stackexchange.com/questions/57385/where-are-system-environment-variables-set-in-mountain-lion</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload