환경 변수의 개념은 그것에 익숙하지 않으며 운영 체제의 환경 변수입니다.
시스템 변수는 Java 자체에 의해 유지되는 변수입니다. System.GetProperty를 통해 가져 오십시오.
다른 운영 체제의 경우 환경 변수의 처리는 사례 둔감 등과 같은 일관성이 없을 수 있습니다.
Java는 환경 변수를 얻습니다
Java의 환경 변수를 얻는 방법은 매우 간단합니다.
System.getenv ()는 모든 환경 변수를 가져옵니다
System.GetEnv (키)는 환경 변수의 값을 가져옵니다
지도 맵 = System.getenv (); 반복자 it = map.entryset (). iterator (); while (it.hasnext ()) {entry entry = (enterd) it.next (); System.out.print (entry.getKey ()+"="); System.out.println (entry.getValue ()); }Windows 시스템 인 경우 인쇄 된 값은 "내 컴퓨터"에서 보이는 환경 변수와 동일합니다.
Java는 시스템 변수를 가져오고 설정합니다
Java의 환경 변수를 얻는 방법도 매우 간단합니다.
system.getProperties () 모든 시스템 변수를 가져옵니다
System.GetProperty (키) 시스템 변수의 값을 가져옵니다
속성 속성 = system.getProperties (); 반복자 it = properties.entryset (). iterator (); while (it.hasnext ()) {entry entry = (enterd) it.next (); System.out.print (entry.getKey ()+"="); System.out.println (entry.getValue ()); }시스템 변수를 얻을 수있을뿐만 아니라 System.setProperty (키, 값)를 통해 필요한 시스템 변수를 설정할 수도 있습니다.
기본적으로 Java로 설정된 시스템 변수 :
다시 채우다
1. .bat에서; .cmd 또는 .sh, 일부 변수는 세트별로 설정됩니다.
예를 들어, Weblogic의 setDomainenv.cmd
sun_java_home = c :/oracle/middleware/jdk160_21을 설정하십시오
환경 변수는 여기에 설정됩니다
2. LOG4J 구성에서 로그 파일의 생성 경로가 때때로 구성됩니다.
예를 들어 $ {log_dir} /logfile.log, 여기에서 log_dir는 시스템 속성의 변수로 대체됩니다.
3. Java 소스 코드를 살펴보십시오. System.getProperties ()를 통해 시스템 변수를 얻으면 안전한 점검이 있습니다.
public static 속성 getProperties () {SecurityManager sm = getSecurityManager (); if (sm! = null) {sm.checkpropertiesaccess (); } 리턴 소품; } 단일 Java 응용 프로그램 테스트 중에 시스템의 보안 관리자가 비어 있습니다.
애플릿이 실행되면 .policy 파일과 함께 권한이 확인됩니다.
빈 SecurityManager를 제공하면 권한 예외가 발생합니다.
public static void main (String [] args) {// todo 자동 생성 메소드 스터브 시스템 .SetSecurityManager (New SecurityManager ()); // SecurityManager sm = system.getSecurityManager (); //system.out.println(sm); System.GetSecurityManager (). CheckProperTiesAccess (); } System.getenv ()와 System.getProperties ()의 차이 public static void main (String [] args) {map m = system.getenv (); for (iterator it = m.keyset (). iterator (); it.hasnext ();) {String key = (string) it.next (); 문자열 값 = (문자열) m.get (키); System.out.println (key +":" +value); } system.out.println ( "------------------------------------------------------- 속성 p = system.getProperties (); for (iterator it = p.keyset (). iterator (); it.hasnext ();) {String key = (string) it.next (); 문자열 값 = (문자열) p.get (키); System.out.println (key +":" +value); }}Ant_home : d :/program/devel/antprocessor_architecture : x86logonserver : // rj-weijianjunhomedrive : c : catalina_home : d : /program/server/tomcat5.5dxsdk_dir : d :/program files/microsoft sdk (2008)/vs80cnts :/Vs80cnts : c 파일/Microsoft Visual Studio 8/Common7/Tools/SessionName : ConsoleHomePath :/Documents and Settings/Settings/AdministratorTMP : C :/Docume ~ 1/admini ~ 1/locals ~ 1/tempwindir : C :/WindowsProcessor_identifier : X86 Family 6 Model 15 Stepping 13, GenUineIntelvs90comntools :/Program Files/Microsoft/Progrome Piles/Progrome 파일 :/Prodert Piles : 9 filesnumber_of_processors : 2comspec : c :/windows/system32/cmd.execomputername : rj-weijianjunos : wind Settings/All UsersLib : C :/Program Files/SQLXML 4.0/bin/processor_level : 6SystemRoot : C :/WindowsClusterLog : C : /Windows/Cluster/Cluster.logappData : C :/Documents/Adveration/Application Datapath : C :/Windows/System32; C; Windows/Windows/Windows; 파일/Microsoft SQL Server/80/도구/Binn/; 8/common7/ide/privateassemblies/; d :/program/devel/flex_sdk2/bin; d :/program/devel/ant/bin; c :/program files/java/jdk1.6.0_07/bin; 파일/java/jdk1.6.0_07fp_no_host_check : noprocessor_revision : 0f0dprogramfiles : c :/program files부동산의 출력은 다음과 같습니다.
--------------------------------- Java.runtime.name:java(tm) 2 런타임 환경, 표준 editionsun.boot.library.path : d :/program files/myeclipse 6.5/jre/binjava.vm. version : 1.5.0_11-11-11-11-3java.vm. 벤더 : Sun Microsystems inc.java.vendor.url : http : //java.sun.com/path.separator :; java.vm.name : java hotspot (tm) 클라이언트 vmfile.encoding.pkg : sun.java.launcher : sun_standarduser.country.patch.patch.patch.patch.patch.patch 2java.vm.specification.name:java Virtual Machine SpecificationUser.dir : d : /dev/eclipse/mye65/workspace/jmxjava.runtime.version : 1.5.0_11-11-b03java.awt.graphicsenv : sun.awt.win32graphicenva 파일/myeclipse 6.5/jre/lib/endorsedos.arch : x86java.io.tmpdir : c : /docume~1/admini~1/locals~1/temp/line.separator : java.vm.specification.vendor : sun microsystems inc.user.user.user.user.sor.name 2003sun.jnu.encoding : gbkjava.library.path : d :/program files/myeclipse 6.5/jre/bin; 파일/Microsoft SQL Server/90/DTS/Binn/; C :/Program Files/Microsoft SQL Server/90/Tools/Binn/; C :/Program Files/Microsoft SQL Server/90/Tools/Binn/; 서버/90/도구/binn/vsshell/common7/ide/; c :/program files/microsoft visual studio 8/common7/ide/privateassemblies/; d :/program/devel/flex_sdk2/bin; d :/program/devel/ant/bin; c :/program 파일/java/jdk1.6.0_07/bin;%jonas_root%/bin/nt; d : /program/devel/ant/binjava.specification.name : java 플랫폼 API Specificationjava.class.version : 49.0sun.management.compiler : Hotspot Compileros.verson. : 5.2USER : 및 settings/administratoruser.timezone : asia/shanghaijava.awt.printerjob : sun.awt.windows.wprinterjobfile.encoding : gbkjava.specification.version : 1.5java.class.path : d :/dev/eclipse/mye65/workspace/jmx/bin; d :/program/bin; b/jmx/jmxtools.jar; d : /program/lib/log/commons-logging-1.1.jar; d : /program/lib/log/log4j-1.2.jar; d :/pro 그램/lib/registry/registry.jaruser.name : administratorjava.vm.specification.version : 1.0java.home : d :/program 파일/myeclipse 6.5/jresun.arch.data.model : 32user.language : zhjava.specification.vendor : sun microsystems inc.awt.toolkit : sun.awt.windows.wtoolkitjava.vm.info : mixed modejava.version : 1.0_1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112 파일/myeclipse 6.5/jre/lib/extsun.boot.class.path : d :/program files/myeclipse 6.5/jre/lib/rt.jar; d :/program files/myeclipse 6.5/jre/i18n.jar; d :/program files/myeclipse 6.5/jre/lib/sunrasign 파일/myeclipse 6.5/jre/lib/jsse.jar; d :/progrent files/myeclipse 6.5/jre/lib/jce.jar; d :/program files/myeclipse 6.5/jre/lib/charsets.jar; d :/program files/myeclipse 6.5/jre/lib/charsets.jar; 6.5/JRE/ClasssJava. Vendor : Sun Microsystems inc.file.separator : /java.vendor.url.bug : http : //java.sun.com/cgi-bin/bugreport.cgisun.io.unicode.encoding : unicodelittlesun.cpu.endian : littlesun.desktop : windowsun.cpu.isalist Pentium+MMX Pentium I486 I386 I86