Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As the location and name of the file differs between platforms and it seems there is no environment variable pointing to it I suppose that your best bet is to look for the file in the filesystem:</p> <pre><code>#!/usr/bin/env python import subprocess import re rtjarPaths = subprocess.check_output(["locate", "rt.jar"]) paths = re.findall('^.*/jre/.*$', rtjarPaths, re.M) print paths vicent@deckard:~$ python findrt.py ['/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar'] </code></pre> <p>The above code works fine for me on my Ubuntu box. It can be easily extended for working on MacOS X too. Other linux distros may require to adapt the code too.</p> <p><strong>Update:</strong> After some googling I've found <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/findingclasses.html" rel="nofollow">in the oracle documentation</a> that the <code>rt.jar</code> file is located in the path stored in the <code>sun.boot.class.path</code> system property. Unfortunately I don't know how to get this property directly from Python or from the command line so I can only provide the following dirty alternative to the previous code.</p> <p>Create and compile PropertiesTest.java:</p> <pre><code>public class PropertiesTest { public static void main(String[] args) throws Exception { String value = System.getProperty("sun.boot.class.path"); System.out.println(value); } } </code></pre> <p>Then execute the following Python script:</p> <pre><code>#!/usr/bin/env python import subprocess import re jrePaths = subprocess.check_output(["java", "PropertiesTest"]) rt = re.findall('(?:.*:)?(.*/(?:rt|classes)\.jar):?', jrePaths) print rt </code></pre> <p>which should work on both Linux and MacOS X platforms. On my Ubuntu system it gives the output </p> <pre><code>['/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar'] </code></pre>
 

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