如何运行加载来自文件的 Java 应用程序环境变量?

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

how to run java application with environment variables loading from file?

问题

我正在构建 Java(jdk 8)应用程序。

我希望能从我的集成开发环境(Intellij IDEA)中以运行/调试模式运行这个应用程序。

我的应用程序使用一些环境变量。

我知道我可以在运行/调试配置中逐一添加这些环境变量 -> 环境变量。

  • 是否可以从文件(比如 env.list 文件)中加载所有这些环境变量?
  • 当在运行/调试模式下运行应用程序时,我如何告诉集成开发环境从文件中加载环境变量?
英文:

I'm building java (jdk 8) application.

I want to run the application (run/debug mode) from my IDE (Intellij IDEA).

My application use some environment variables.

I know I can add the environment variables one by one in the Run/Debug configurations -> environment variables.

  • Is it possible to load all those environment variables from file (i.e env.list file) ?
  • How can I tell the IDE to load the environment variables from file when running the application in Run/Debug mode ?

答案1

得分: 2

现在在集成开发环境(IDE)中没有这样的选择。我们必须手动在运行/调试配置中添加所有这些内容。如果你愿意,可以将其作为Gradle/Maven的一部分添加进去,从那里你可以执行所有预期的功能,并在运行/调试配置中配置该任务。只有这样才能解决你的问题。

英文:

Right now there is no choice like that in IDEs.
We have to manually feed all those stuffs in the Run/Debug configuration.
If you want you can add it as part of your gradle / maven from there you can do all those expected functionalitites and configure that task in the Run/Debug configuration.
That only will solve your problem.

答案2

得分: 1

没有直接的方法来做这件事。

我脑海中唯一想到的是:

  • 我不知道你的IDEA版本,但有像EnvFile这样的插件可以做到。但是这些文件的格式是有限的。

如果你不想直接从IDE中使用它,你可以编写代码:

英文:

There is no direct way to do this.

The only things that comes to my mind is:

  • I don't know the version of your IDEA but there are plugins for that like this one, EnvFile. But the format of these files are limited.

If you don't want to use it from directly from IDE you can code:

huangapple
  • 本文由 发表于 2020年9月9日 13:10:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63805109.html
匿名

发表评论

匿名网友

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

确定