什么系统环境存储InetAddress.getLocalHost().GetCanonicalHostName()的值
What system environment stores the value of InetAddress.getLocalHost().GetCanonicalHostName()
我试图了解哪些系统变量具有此值。我执行这段代码并得到 some_string.
InetAddress.getLocalHost().GetCanonicalHostName();
之后我打印我所有的系统环境
System.getenv().forEach((k, v) -> System.out.println("K = " + k + "
V = " + v));
我找到所有具有 some_string 的变量,并将所有值替换为
@ClassRule
public final static EnvironmentVariables ENVIRONMENT_VARIABLES = new EnvironmentVariables();
final String pcNameForEnv = "test-pc-name";
ENVIRONMENT_VARIABLES.set("USERDOMAIN", pcNameForEnv);
但是我的测试失败了
@Test
public void getMachineNameFromEnv() {
final String pcNameForEnv = "test-pc-name";
ENVIRONMENT_VARIABLES.set("USERDOMAIN", pcNameForEnv);
final String machineName = networkUtil.getPCNetworkName();
assertEquals(pcNameForEnv, machineName);
}
我发现我需要更换这个版本:
"user.name",
"user.home",
"LOGONSERVER",
"COMPUTERNAME",
"USERDOMAIN_ROAMINGPROFILE",
"USERDOMAIN",
"COMPUTERNAME",
"MACHINENAME";
但这对我也没有帮助。
您不能设置环境变量让Java认为您在不同的机器上。来自 java.lang.InetAddress -
Returns the address of the local host. This is achieved by retrieving the name of the host from the system, then resolving that name into an InetAddress.
我试图了解哪些系统变量具有此值。我执行这段代码并得到 some_string.
InetAddress.getLocalHost().GetCanonicalHostName();
之后我打印我所有的系统环境
System.getenv().forEach((k, v) -> System.out.println("K = " + k + " V = " + v));
我找到所有具有 some_string 的变量,并将所有值替换为
@ClassRule public final static EnvironmentVariables ENVIRONMENT_VARIABLES = new EnvironmentVariables();
final String pcNameForEnv = "test-pc-name"; ENVIRONMENT_VARIABLES.set("USERDOMAIN", pcNameForEnv);
但是我的测试失败了
@Test public void getMachineNameFromEnv() { final String pcNameForEnv = "test-pc-name"; ENVIRONMENT_VARIABLES.set("USERDOMAIN", pcNameForEnv); final String machineName = networkUtil.getPCNetworkName(); assertEquals(pcNameForEnv, machineName); }
我发现我需要更换这个版本:
"user.name", "user.home", "LOGONSERVER", "COMPUTERNAME", "USERDOMAIN_ROAMINGPROFILE", "USERDOMAIN", "COMPUTERNAME", "MACHINENAME";
但这对我也没有帮助。
您不能设置环境变量让Java认为您在不同的机器上。来自 java.lang.InetAddress -
Returns the address of the local host. This is achieved by retrieving the name of the host from the system, then resolving that name into an InetAddress.