简体   繁体   English

如何使用从文件加载的环境变量运行java应用程序?

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

I'm building java ( jdk 8 ) application.我正在构建 java ( jdk 8 ) 应用程序。

I want to run the application (run/debug mode) from my IDE ( Intellij IDEA ).我想从我的 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 (ie env.list file) ?是否可以从文件(即 env.list 文件)加载所有这些环境变量?
  • How can I tell the IDE to load the environment variables from file when running the application in Run/Debug mode ?在运行/调试模式下运行应用程序时,如何告诉 IDE 从文件加载环境变量?

Right now there is no choice like that in IDEs.现在在 IDE 中没有这样的选择。 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.如果您愿意,可以从那里将其添加为 gradle/maven 的一部分,您可以执行所有这些预期的功能并在运行/调试配置中配置该任务。 That only will solve your problem.那只会解决你的问题。

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 .我不知道你的 IDEA 的版本,但有像这样的插件, EnvFile But the format of these files are limited.但是这些文件的格式是有限的。

If you don't want to use it from directly from IDE you can code:如果您不想直接从 IDE 使用它,您可以编写代码:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM