在环境配置中我们经常需要知道或者设置系统属性值和环境变量。系统属性值是在同一个Java process里面有效的全局变量。而环境变量则是对于整个操作系统中所有进程都可见的,就如同你在OS里面设置的一样。因此除非必要,或者你确实需要环境变量,比如classpath和path,一般推荐使用properties。比如log4j的属性文件的使用。
下面的代码可以打印出所有的系统变量和环境变量:
package jdk.lang;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
public class SystemProperties {
public static void main(String[] args) {
printAllProperties();
printALlEnvs();
}
private static void printALlEnvs() {
Map<String, String> envs = System.getenv();
Iterator<String> keys = envs.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
String value = System.getenv(key);
System.out.println(String.format("%s: %s", key, value));
}
}
private static void printAllProperties() {
Properties properties = System.getProperties();
Enumeration<Object> keys = properties.keys();
while (keys.hasMoreElements()) {
String key = keys.nextElement().toString();
String value = System.getProperty(key);
System.out.println(String.format("%s: %s", key, value));
}
}
}
分享到:
相关推荐
系统环境变量(quasar-app-extension-system-environment-variables) ==== 从系统加载环境变量,并通过process.env使它们可用。 最适合在CI / CD环境中构建 在某些情况下,例如在CI环境中工作时,我们可能希望从...
Java Methods-Data Types, Variables, and Arithmetic.ppt
前端开源库-postcss-variablespostss变量,postss插件,用于将变量转换为css
3rd Edition - Probability, Random Variables and Stochastic
设置Windows环境变量工具 NVM - eNvironment Variables Manager 1.可以设置用户变量、系统变量,非常方便。 2.可以把环境变量导出成XML文件,不过不能导入 类似的工具有EnvMan,RapidEE。 此工具的源代码可以在...
05 Coding Challenge #2 - Data Types, Variables and Arrays
信号与系统教学课件:1-3 Transformation of variables.ppt
前端开源库-postcss-css-variablespostcss css变量,postcss插件,用于将css自定义属性(css变量)语法转换为静态表示形式
安装完JDK以后,需要配置Java的系统的全局变量。一共需要加三个: JAVA_HOME:JDK的安装路径 Path:JAVA的二进制文件路径,就是JDK的安装...在System Properties的Advanced选项卡里,点击Environment Variables按键。
It describes in particular the mechanisms of synchronization (cooperative and competitive) and sharing of data (internal class, static variables) between threads in Java. He then discusses the use of...
使用Create React App,Docker(和Nginx)的运行时环境变量该存储库显示了如何实现运行时环境变量。 与传统解决方案不同,这允许您通过环境变量配置React应用程序,而无需再次构建。 该存储库在Medium博客文章中进行...
AI1103-Probability-and-random-variables
Java Applets and the Internet 7 A Short History of Java 9 Common Misconceptions about Java 11 Chapter 2: The Java Programming Environment 15 Installing the Java Development Kit 16 Choosing a ...
Setting Environment Variables 2-11 Oracle Universal Installer (OUI) 2-13 Installing the Oracle Software 2-14 Database Configuration Options 2-15 iii Oracle Internal & Oracle Academy Use Only.............
Google Cloud Functions环境变量测试 测试使用环境变量的Google Cloud Function(最近在Google Cloud上添加的功能)。 另外,请务必查看。 我还写了的。 设置 确保您已安装Google的gcloud命令并将其更新到最新版本...
Laravel开发-laravel-variables Laravel项目中的变量/设置管理
安装npm install find-unused-sass-variables --save-dev用法find-unused-sass-variables folder [, folder2...] --ignore " $my -var, $my -second-var "# orfusv folder [, folder2...]API const fusv = require ...
了解如何在 Matlab 中使用变量。 具体来说,我们学习如何从内存中清除变量,以便我们可以在本课的计算中使用它们。
AI1103-Probability-and-Random-Variables