title: discover path for symbol
body: <p>My question is whether Java doesn't have something like <code>sys.path</code> in Python, or even more specific ways of finding out where a symbol comes from.  I've seen answers that say "load this tool" from some outside source, but it seems like the language could have this ability.</p>
  
  <p>The impetus for this is a standard <code>Hello.java</code> example on my Desktop that prints "Hello, world!" after compiling and running, when the code itself was "Hello world!" (no comma).  Like high school English or something.  Deletion of the <code>Hello.class</code> file I thought was being run changed nothing.  Ditto with <code>Hello.java</code> there.  Even weirder, when it is present, the compiler finds the source file <code>Hello.java</code> on my Desktop first in its search path.  <code>Hello.class</code> <em>is</em> updated when I run <code>javac Hello.java</code>.  So how do I find my mystery file?  Relent and use <code>grep</code>?</p>
  
  <p>Update:</p>
  
  <p>So, I should have guessed that the troublesome file would be (this is OS X) in <code>/Library/Java/Extensions</code>, or my user-specific directory (prepend <code>~</code>).  Having found a candidate, I examined it with </p>
  
  <pre><code>&gt; jar tf /Library/Java/Extensions/obscureName.jar &gt; x.txt
  &gt; grep "Hello" x.txt
  Hello.class
  </code></pre>
  
  <p>Not knowing this, the proper approach is to search for a <em>different</em> system property, namely <code>java.ext.dirs</code> or possibly <code>java.library.path</code>.  The crucial part of the code being:</p>
  
  <pre><code>Properties ps = System.getProperties();
  String sep = ps.getProperty("path.separator");
  String fileName;
  String[] pL = { "java.class.path",
                  "java.ext.dirs",
                  "java.library.path" };
  String[] array;
  for (String property:pL) {
      System.out.println(property);
      array = ps.getProperty(property).split(sep);
      for (String path:array) {
          System.out.println(path);
          File[] files = new File(path).listFiles();
          if (files != null) {
              for (File f:files) {
                  fileName = f.getName();
  </code></pre>