设置远程运行代码时的IntelliJ环境变量

huangapple go评论76阅读模式
英文:

Setting IntelliJ environment variables when running the code remotely

问题

我有一台机器,在这台机器上我在写代码,并且我通过端口转发在另一台机器上本地执行这些代码。在这种情况下,如果我在本地机器的IntelliJ中设置了环境变量(我写代码的那台机器),那么远程机器会读取到这些变量吗?基本上我对IntelliJ设置这个环境变量的位置感到困惑,以及这个变量是否是全局的?我顺便说一下,我是在“运行配置”下设置这个环境变量的。

英文:

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.

答案1

得分: 1

IntelliJ IDEA的TestNG运行配置不会将环境变量传递到远程机器,它们只会设置给本地机器。您需要从在远程系统上运行的代码中进行设置。

英文:

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.

答案2

得分: 0

一个进程从启动它的操作系统获取环境变量。这些变量在进程启动之前必须在远程计算机上设置好。

这就是为什么你只会在IntelliJ的本地配置(例如“应用程序”,“JUnit”等)中看到用于输入环境变量的文本框。对于“远程”配置,没有这样的文本框。

“远程”配置只会通过调试端口连接到远程进程,而在这种情况下,进程必须已经在运行。

你需要在远程计算机上运行这个:

export VARIABLE=value
java -cp classpath MainClass
英文:

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

huangapple
  • 本文由 发表于 2020年8月29日 02:23:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63639090.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定