Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This isn't a totally unreasonable question, but there's no good answer, so for posterity, I'll make an attempt at explaining <em>why</em> you got stuck, and why it won't work.</p> <ol> <li><p><code>java.library.path</code> isn't guaranteed to be set from an environment variable at all. You can specify what you want it to be with <code>-Djava.library.path=</code>. More than likely, this is what you <em>really</em> want to do anyway. That's why the option exists.</p></li> <li><p>It turns out (on windows at least), that the environment variable you're looking for isn't just used unmolested. Try this code.</p> <pre><code>package com.stackoverflow; import java.util.Map; public class LibPathFinder { public static void main(String[] args) { String javaLibPath = System.getProperty("java.library.path"); Map&lt;String, String&gt; envVars = System.getenv(); System.out.println(envVars.get("Path")); System.out.println(javaLibPath); for (String var : envVars.keySet()) { System.err.println("examining " + var); if (envVars.get(var).equals(javaLibPath)) { System.out.println(var); } } } } </code></pre> <p>You'll note that when it runs, the first two things it prints are different. If Java is using the windows <code>PATH</code> variable, it's fiddling with the value first. I gave up investigating what was going on. The point was, there wasn't an environment variable that exactly matched the <code>java.library.path</code>. I didn't try on Linux or OSX, your mileage may vary</p></li> <li><p>It's really not very nice to mess with somebody's environment variables like this. They're used for the entire shell, so you're committing your users to have your shared library on their environment, but only <em>sometimes</em>. The only real reason to change <code>java.library.path</code> is to add native libraries. If you're using native libraries, then you have OS-specific code already (it has to be compiled for the platform, right?), so you've really already given up the fight for "no platform-specific edge cases". The best thing to do is to put your native library in a place where the system path (whatever that may be) will already find it, or add your library's path to it <em>permanently</em> with an installer of some kind. If you don't want to do either of those things, then I'd suggest using a variation of @malat's code, printing the real <code>java.library.path</code>, and then appending your path to that result in your script, and then use the <code>-D</code> option to set it for the real program run.</p></li> </ol>
 

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