Setting IntelliJ environment variables when running the code remotely

528 views Asked by At

I have a machine on which I'm writing the code and I'm executing the code on a different machine locally by using port forwarding. In this case, if I set IntelliJ environment variables in my local machine IntelliJ (The machine in which I'm writing the code), will it be read on the remote machine? Basically I'm confused about where IntelliJ sets this environment variable and whether its global?

I have set the environment variable under "Run Configurations" by the way.

2

There are 2 answers

0
CrazyCoder On

IntelliJ IDEA TestNG run configuration does nothing to pass the environment variables to the remote machine, they will be set for the local machine only. You need to do it from your code that runs on the remote system.

0
jurez On

A process gets environment variables from the operating system that starts it. They have to be set on remote machine before the process is started.

That's why you can see a text box for entering environment variables in IntelliJ only for local configurations (e.g. "Application", "JUnit" etc.). There is no such text box for "Remote" configurations.

"Remote" configurations only attach to remote process via debugging port, and in this case the process has to be already running.

You need to run this on the remote machine:

export VARIABLE=value
java -cp classpath MainClass