首先,使用该getenv()
方法获取环境变量-
System.out.println("PATH = " + System.getenv("PATH"));
现在,获取关键和值。循环获取环境变量列表-
Map e = System.getenv(); for (Iterator i = e.entrySet().iterator(); i.hasNext();) { Map.Entry mapEntry = (Map.Entry) i.next(); System.out.println(mapEntry.getKey() + " = " + mapEntry.getValue()); }
以下是使用Map Collection检索环境变量的示例-
import java.util.Iterator; import java.util.Map; public class Demo { public static void main(String args[]) { System.out.println("PATH = " + System.getenv("PATH")); //环境变量 Map e = System.getenv(); for (Iterator i = e.entrySet().iterator(); i.hasNext();) { Map.Entry mapEntry = (Map.Entry) i.next(); System.out.println(mapEntry.getKey() + " = " + mapEntry.getValue()); } } }
输出结果
Note: The output varies system to system. PATH = /home/cg/root/GNUstep/Tools:/usr/GNUstep/Local/Tools:/usr/GNUstep/System/Tools:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/webmaster/.local/bin:/home/webmaster/bin:/usr/local/scriba/bin:/usr/local/smlnj/bin:/usr/local/bin/std:/usr/local/bin/extra:/usr/local/fantom/bin:/usr/local/dart/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/opt/mono/bin:/opt/mono/lib/mono/4.5:/usr/local/bin:.:/usr/libexec/sdcc:/usr/local/icon-v950/bin:/usr/local/mozart/bin:/opt/Pawn/bin:/opt/jdk1.7.0_75/bin:/opt/jdk1.7.0_75/jre/bin:/opt/pash/Source/PashConsole/bin/Debug/::/usr/local/sml/bin:/usr/local/flex/bin:/usr/local/gcc-4.8.2/bin:/usr/share/java:.:/usr/share/java:/usr/lib/jvm/java/lib:/usr/lib/jvm/java/jre/lib:/usr/local/bin:/usr/local/mozart/bin:/usr/local/go/bin:/usr/local/factor/:/usr/local/groovy-2.4.0-beta-3/bin:/opt/Pawn/bin/:/usr/local/icon-v950/bin:/usr/local/lib/mono/4.0:/usr/lib64/qtSetEnv C.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/Pawn/bin:/usr/local/scala-2.11.5/bin:/usr/libexec/gcc/x86_64-redhat-linux/4.8.2:/home/cg/root/GNUstep/Tools:/usr/GNUstep/Local/Tools:/usr/GNUstep/System/Tools:/usr/local/bin:/usr/libexec/gcc/x86_64-redhat-linux/4.9.2 PATH = /home/cg/root/GNUstep/Tools:/usr/GNUstep/Local/Tools:/usr/GNUstep/System/Tools:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/webmaster/.local/bin:/home/webmaster/bin:/usr/local/scriba/bin:/usr/local/smlnj/bin:/usr/local/bin/std:/usr/local/bin/extra:/usr/local/fantom/bin:/usr/local/dart/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/opt/mono/bin:/opt/mono/lib/mono/4.5:/usr/local/bin:.:/usr/libexec/sdcc:/usr/local/icon-v950/bin:/usr/local/mozart/bin:/opt/Pawn/bin:/opt/jdk1.7.0_75/bin:/opt/jdk1.7.0_75/jre/bin:/opt/pash/Source/PashConsole/bin/Debug/::/usr/local/sml/bin:/usr/local/flex/bin:/usr/local/gcc-4.8.2/bin:/usr/share/java:.:/usr/share/java:/usr/lib/jvm/java/lib:/usr/lib/jvm/java/jre/lib:/usr/local/bin:/usr/local/mozart/bin:/usr/local/go/bin:/usr/local/factor/:/usr/local/groovy-2.4.0-beta-3/bin:/opt/Pawn/bin/:/usr/local/icon-v950/bin:/usr/local/lib/mono/4.0:/usr/lib64/qtSetEnv C.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/Pawn/bin:/usr/local/scala-2.11.5/bin:/usr/libexec/gcc/x86_64-redhat-linux/4.8.2:/home/cg/root/GNUstep/Tools:/usr/GNUstep/Local/Tools:/usr/GNUstep/System/Tools:/usr/local/bin:/usr/libexec/gcc/x86_64-redhat-linux/4.9.2 KOTLIN_HOME = /root/.sdkman/candidates/kotlin/current TERM = xterm SMLROOT = /usr/local/smlnj/bin XFILESEARCHPATH = /usr/dt/app-defaults/%L/Dt LIBRARY_COMBO = gnu-gnu-gnu LANG = en_US.UTF-8 GNUSTEP_NETWORK_ROOT = /usr/GNUstep/Network GNUSTEP_SYSTEM_ROOT = /usr/GNUstep/System LD_LIBRARY_PATH = /home/cg/root/GNUstep/Library/Libraries:/usr/GNUstep/Local/Library/Libraries:/usr/GNUstep/System/Library/Libraries:/usr/local/lib:/usr/lib FBR = f26 GUILE_LOAD_PATH = /home/cg/root/GNUstep/Library/Libraries/Guile:/usr/GNUstep/Local/Library/Libraries/Guile:/usr/GNUstep/System/Library/Libraries/Guile GNUSTEP_IS_FLATTENED = yes GNUSTEP_FLATTENED = yes PWD = /home/cg/root/8005768 GNUSTEP_MAKEFILES = /usr/GNUstep/System/Library/Makefiles INFOPATH = /usr/GNUstep/System/Library/Documentation/info::/usr/GNUstep/Local/Library/Documentation/info::/home/cg/root/GNUstep/Library/Documentation/info: HAXE_LIBRARY_PATH = /usr/share/haxe/std:. _ = /usr/bin/timeout SDKMAN_CANDIDATES_DIR = /root/.sdkman/candidates GNUSTEP_HOST_VENDOR = unknown HAXE_STD_PATH = /usr/local/bin/std:/usr/local/bin/extra FGC = f26 DART_SDK = /usr/local/dart DISTTAG = f26container OLDPWD = / SDKMAN_PLATFORM = Linux64
问题内容: 我正在尝试遵循一个教程,它说: 有几种加载凭证的方法。 从环境变量加载, 从磁盘上的JSON文件加载, 密钥需要如下: …这意味着,如果您正确设置环境变量,则根本不需要管理应用程序中的凭据。 基于一些谷歌搜索,看来我需要将变量设置为?如何以及在哪里设置这些凭据?请举例。 问题答案: 使用环境变量(在这种情况下)将凭据传递给您的应用程序。并且都可以分别从和访问。您无需对其进行编辑,只需访
这是一个按照字母顺序排序的,由Autoconf检查的环境变鼠的列表。 a AC_MACRODIR, AC_MACRODIR, AC_MACRODIR, AC_MACRODIR, AC_MACRODIR, AC_MACRODIR c CONFIG_FILES CONFIG_HEADERS CONFIG_SHELL CONFIG_SITE CONFIG_STATUS s SIMPLE_BACKUP_S
我试着去看一本教程,上面写着: 有几种方法可以加载凭据。 null 根据一些谷歌搜索,我似乎需要设置中的变量?如何以及在何处设置这些凭据?请举例。
问题内容: 我有以下情形:我定义了一个env变量,并想在nginx块中使用它。参考nginx文档,我在文件中使用伪指令,如下所示: 现在我想将变量用于。我尝试如下所示: 但我最终收到以下错误消息: 问题答案: 正确的用法是,但是从nginx.conf设置的环境变量不能在服务器,位置或http块中使用。 如果使用openresty包(包括Lua),则可以使用环境变量。
问题内容: 我一直在阅读官方文档,但无法找到有关环境变量的任何信息。显然,有一些社区项目支持环境变量,但这对我来说可能是过大了。所以我想知道在使用Vue CLI创建的项目上是否有一些简单的开箱即用的功能可以正常工作。 例如,我可以看到,如果执行以下操作,则会打印出正确的环境,这意味着已经设置好了吗? 我对环境变量和Node有点陌生。 仅供参考,使用Vue CLI 3.0 beta版。 问题答案:
问题内容: 如何使用变量配置Web服务器(Linux服务器)? 如何设置使用? 问题答案: 是一些服务器和其他Java应用程序附加到执行命令的调用的标准环境变量。 例如在tomcat中,如果您定义,启动脚本将执行 如果您在Linux / OSX上运行,则可以在调用启动脚本之前通过执行以下操作来设置JAVA_OPTS: 只要打开控制台,此操作将一直持续。要使其更永久,可以将其添加到〜/ .profi