4

I have a cross-platform Java application that relies on some native (C++) libraries for calling functions that perform complex scientific calculations. The native libraries are accessed using JNI (with SWIG-generated glue code). The libraries access several environment variables for configuration and location of various data tables, etc. I would like my Java application to be able to set these environment variables, at least in the context of the JNI libraries. This would be easy if Java provided a way to set environtment variables in it's own shell/context, but it doesn't.

I've seen answers to similar questions that require changing variables for Java itself or for child processes. This question is different because it relates specifically to JNI-called code. My guess is that the situation is identical because the JNI code presumably runs in the same environment as the Java application itself. However, I thought I'd ask just in case there is some JNI setting or method that could do this.

Community
  • 1
  • 1
drwatsoncode
  • 4,721
  • 1
  • 31
  • 45

1 Answers1

1

Your guess is correct. Environment variables are tied to the process. No difference between JNI and not-JNI.

You should be able to use another JNI library to set the environment for the other library running in the same process to pick up.

user2543253
  • 2,143
  • 19
  • 20