I define the CATALINA_HOME system variable, which refers to the tomcat installation directory on my OS (end of the 64-bit version of Windows 7), now I want to get it through java, my code is below:
System.out.println(System.getenv("CATALINA_HOME"));
it returns null, I'm sure this variable exists on my system, I type set catalina_home in the cmd console, it accurately shows the value assigned to it.
So why can't I get it, or is there another way to get the system env variable?
PS: below are all the variables obtained using System.getenv() .
Map<String, String> env = System.getenv(); for (String key : env.keySet()) { System.out.println(key + ":" + env.get(key)); } System.out.println(System.getenv("CATALINA_HOME"));
output:
USERPROFILE:C:\Users\chorusheng ProgramData:C:\ProgramData PATHEXT:.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC JAVA_HOME:C:\Program Files\Java\jdk1.6.0_20 ProgramFiles(x86):C:\Program Files (x86) TEMP:C:\Users\CHORUS~1\AppData\Local\Temp SystemDrive:C: ProgramFiles:C:\Program Files Path:C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;d:\Program Files (x86)\KOUTON\CTBS Standard Client;C:\Program Files (x86)\PC Connectivity Solution\;D:\oracle\product\11.2.0\dbhome_1\bin;C:\Program Files (x86)\Common Files\NetSarang;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\EgisTec BioExcess\;C:\Program Files (x86)\EgisTec BioExcess\x64;C:\Program Files (x86)\Common Files\Thunder Network\KanKan\Codecs;d:\Program Files (x86)\Tencent\QQPCMgr\6.6.2150.401;D:\Program Files (x86)\TortoiseSVN\bin;d:\Program Files (x86)\DigiWin OpenVPN\bin;d:\Program Files (x86)\Tencent\QQPCMgr\6.6.2150.401;F:\chega\eclipsej2ee3.7; HOMEDRIVE:C: DYNA_HOME:E:\plm PROCESSOR_REVISION:2502 USERDOMAIN:chorus ALLUSERSPROFILE:C:\ProgramData ProgramW6432:C:\Program Files PROCESSOR_IDENTIFIER:Intel64 Family 6 Model 37 Stepping 2, GenuineIntel SESSIONNAME:Console TMP:C:\Users\CHORUS~1\AppData\Local\Temp CommonProgramFiles:C:\Program Files\Common Files CLASSPATH:.;C:\Program Files\Java\jdk1.6.0_20\lib\dt.jar;C:\Program Files\Java\jdk1.6.0_20\lib\tools.jar; LOGONSERVER:\\CHORUS PROCESSOR_ARCHITECTURE:AMD64 FP_NO_HOST_CHECK:NO OS:Windows_NT HOMEPATH:\Users\chorusheng PROCESSOR_LEVEL:6 CommonProgramW6432:C:\Program Files\Common Files 1830B7BD-F7A3-4c4d-989B-C004DE465EDE:f44:431b280 LOCALAPPDATA:C:\Users\chorusheng\AppData\Local COMPUTERNAME:CHORUS windir:C:\Windows SystemRoot:C:\Windows asl.log:Destination=file NUMBER_OF_PROCESSORS:4 USERNAME:chorusheng PUBLIC:C:\Users\Public PSModulePath:C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ CommonProgramFiles(x86):C:\Program Files (x86)\Common Files ComSpec:C:\Windows\system32\cmd.exe APPDATA:C:\Users\chorusheng\AppData\Roaming null
as we can see, the last line is null, which is the value of the CATALINA_HOME variable.
PS: my tomcat is not installation.
hiway source share