Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31544

Re: how to set LD_LIBRARY_PATH within the Java program?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: how to set LD_LIBRARY_PATH within the Java program?
Date 2015-04-09 13:20 -0400
Organization A noiseless patient Spider
Message-ID <mg6cbb$576$1@dont-email.me> (permalink)
References <579a6f03-93e3-4b8c-81d8-c854af1b7654@googlegroups.com>

Show all headers | View raw


On 4/9/2015 11:28 AM, John wrote:
> Hi:
>
> I need to set linux environment variable LD_LIBRARY_PATH within my Java program. The reason is that the Java program calls some linux program which dynamically links to other *.so files. I could do this on the terminal first:
>
> export LD_LIBRARY_PATH=/fs/great/lib:${LD_LIBRARY_PATH}
>
> For some reason, I don't want to do it this way. I want to do it within the Java program. I googled and saw this hacking way,
>
> http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java
>
> People say it works great. But I don't understand his code, posted below. How to use it in my case. Thank you.
>[...]

     People who say "it works great" must be using it for purposes
rather different from yours, or must have a different notion of
what "great" means.  The code (if it works at all) will modify
some Java maps in Java's memory, but will not affect the "real"
environment that lives "out there" in Linux or Windows or whatever.
It will change Java's read-only (supposedly) copy of the external
environment, but won't change that external environment -- and since
the library loader will consult the external environment's value of
LD_LIBRARY_PATH, changing Java's internal copy won't help you.

     You might, I guess, inspect LD_LIBRARY_PATH yourself, and if it
isn't what you want you could set up a ProcessBuilder with the
desired value and re-launch your program as a sub-process.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

how to set LD_LIBRARY_PATH within the Java program? John <xsli2@yahoo.com> - 2015-04-09 08:28 -0700
  Re: how to set LD_LIBRARY_PATH within the Java program? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-09 13:20 -0400
  Re: how to set LD_LIBRARY_PATH within the Java program? "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2015-04-09 16:17 -0500
    Re: how to set LD_LIBRARY_PATH within the Java program? Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-04-10 11:19 +0000

csiph-web