Java – Obtenha informações do sistema operacional, usuário e do Java do cliente facilmente com a API System Properties.

As informações do sistema operacional, usuário e particulariedades do Java do cliente podem ser acessadas com uso da API System Properties, mas especificamente o método System.getProperty(String chave) o qual trabalha com o conceito de chave-valor. Basta informar a chave (veja relação abaixo) na assinatura do método e obter o valor correspondente.  No final do post disponibilizei uma implementação dos uso das propriedades para ilustrar o uso da API :-).

Chave Significado
file.separator Character that separates components of a file path. This is “/” on UNIX and “\” on Windows.
java.io.tmpdir Default temp file path
java.home Installation directory for Java Runtime Environment (JRE)
java.class.version Java class format version number
java.class.path Path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in the path.separator property.
java.home Java installation directory
java.specification.name Java Runtime Environment specification name
java.specification.vendor Java Runtime Environment specification vendor
java.specification.version Java Runtime Environment specification version
java.vendor Java Runtime Environment vendor
java.version Java Runtime Environment version
java.vendor.url Java vendor URL
java.vm.name Java Virtual Machine implementation name
java.vm.vendor Java Virtual Machine implementation vendor
java.vm.version Java Virtual Machine implementation version
java.vm.specification.name Java Virtual Machine specification name
java.vm.specification.vendor Java Virtual Machine specification vendor
java.vm.specification.version Java Virtual Machine specification version
java.vendor JRE vendor name
java.vendor.url JRE vendor URL
java.version JRE version number
line.separator Line separator (“\n” on UNIX)
java.library.path List of paths to search when loading libraries
java.compiler Name of JIT compiler to use
os.arch Operating system architecture
os.name Operating system name
os.version Operating system version
java.ext.dirs Path of extension directory or directories
path.separator Path separator character used in java.class.path
line.separator Sequence used by operating system to separate lines in text files
user.name User account name
user.dir User’s current working directory
user.home User’s home directory
public class ExemploProperties {

	/**
	 * @param args
	 * @author Ricardo Spinoza
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("awt.toolkit="+System.getProperty("awt.toolkit"));
		System.out.println("file.encoding="+System.getProperty("file.encoding"));
		System.out.println("file.encoding.pkg="+System.getProperty("file.encoding.pkg"));
		System.out.println("file.separator="+System.getProperty("file.separator"));
		System.out.println("file.separator="+System.getProperty("file.separator"));
		System.out.println("java.awt.graphicsenv="+System.getProperty("java.awt.graphicsenv"));
		System.out.println("java.awt.printerjob="+System.getProperty("java.awt.printerjob"));
		System.out.println("java.class.path="+System.getProperty("java.class.path"));
		System.out.println("java.class.version="+System.getProperty("java.class.version"));
		System.out.println("java.endorsed.dirs="+System.getProperty("java.endorsed.dirs"));
		System.out.println("java.ext.dirs="+System.getProperty("java.ext.dirs"));
		System.out.println("java.home="+System.getProperty("java.home"));
		System.out.println("java.io.tmpdir="+System.getProperty("java.io.tmpdir"));
		System.out.println("java.library.path="+System.getProperty("java.library.path"));
		System.out.println("java.runtime.name="+System.getProperty("java.runtime.name"));
		System.out.println("java.runtime.version="+System.getProperty("java.runtime.version"));
		System.out.println("java.specification.name="+System.getProperty("java.specification.name"));
		System.out.println("java.specification.vendor="+System.getProperty("java.specification.vendor"));
		System.out.println("java.specification.version="+System.getProperty("java.specification.version"));
		System.out.println("java.vendor="+System.getProperty("java.vendor"));
		System.out.println("java.vendor="+System.getProperty("java.vendor"));
		System.out.println("java.vendor.url="+System.getProperty("java.vendor.url"));
		System.out.println("java.vendor.url="+System.getProperty("java.vendor.url"));
		System.out.println("java.vendor.url.bug="+System.getProperty("java.vendor.url.bug"));
		System.out.println("java.version="+System.getProperty("java.version"));
		System.out.println("java.version="+System.getProperty("java.version"));
		System.out.println("java.vm.info="+System.getProperty("java.vm.info"));
		System.out.println("java.vm.name="+System.getProperty("java.vm.name"));
		System.out.println("java.vm.specification.name="+System.getProperty("java.vm.specification.name"));
		System.out.println("java.vm.specification.vendor="+System.getProperty("java.vm.specification.vendor"));
		System.out.println("java.vm.specification.version="+System.getProperty("java.vm.specification.version"));
		System.out.println("java.vm.vendor="+System.getProperty("java.vm.vendor"));
		System.out.println("java.vm.version="+System.getProperty("java.vm.version"));
		System.out.println("line.separator="+System.getProperty("line.separator"));
		System.out.println("os.arch="+System.getProperty("os.arch"));
		System.out.println("os.arch="+System.getProperty("os.arch"));
		System.out.println("os.name="+System.getProperty("os.name"));
		System.out.println("os.version="+System.getProperty("os.version"));
		System.out.println("path.separator="+System.getProperty("path.separator"));
		System.out.println("path.separator="+System.getProperty("path.separator"));
		System.out.println("sun.arch.data.model="+System.getProperty("sun.arch.data.model"));
		System.out.println("sun.boot.class.path="+System.getProperty("sun.boot.class.path"));
		System.out.println("sun.boot.library.path="+System.getProperty("sun.boot.library.path"));
		System.out.println("sun.cpu.endian="+System.getProperty("sun.cpu.endian"));
		System.out.println("sun.cpu.isalist="+System.getProperty("sun.cpu.isalist"));
		System.out.println("sun.desktop="+System.getProperty("sun.desktop"));
		System.out.println("sun.io.unicode.encoding="+System.getProperty("sun.io.unicode.encoding"));
		System.out.println("sun.jnu.encoding="+System.getProperty("sun.jnu.encoding"));
		System.out.println("sun.management.compiler="+System.getProperty("sun.management.compiler"));
		System.out.println("sun.os.patch.level="+System.getProperty("sun.os.patch.level"));
		System.out.println("user.country="+System.getProperty("user.country"));
		System.out.println("user.dir="+System.getProperty("user.dir"));
		System.out.println("user.home="+System.getProperty("user.home"));
		System.out.println("user.language="+System.getProperty("user.language"));
		System.out.println("user.name="+System.getProperty("user.name"));
		System.out.println("user.timezone="+System.getProperty("user.timezone"));
		System.out.println("user.variant="+System.getProperty("user.variant"));
	}
}

O resultado do programa no meu ambiente:

awt.toolkit=sun.awt.windows.WToolkit
file.encoding=Cp1252
file.encoding.pkg=sun.io
file.separator=\
file.separator=\
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.awt.printerjob=sun.awt.windows.WPrinterJob
java.class.path=C:\Area51\projetosEclipse\workspace\test\bin;C:\Area51\projetosEclipse\workspace\test\jai_codec.jar;C:\Area51\projetosEclipse\workspace\test\jai_core.jar
java.class.version=50.0
java.endorsed.dirs=C:\Arquivos de programas\Java\jre6\lib\endorsed
java.ext.dirs=C:\Arquivos de programas\Java\jre6\lib\ext;C:\Windows\Sun\Java\lib\ext
java.home=C:\Arquivos de programas\Java\jre6
java.io.tmpdir=C:\Users\RICARD~1\AppData\Local\Temp\
java.library.path=C:\Arquivos de programas\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\Dell\DW WLAN Card;C:\Program Files\Common Files\Roxio Shared\OEM\DLLShared\;C:\Program Files\Common Files\Roxio Shared\OEM\DLLShared\;C:\Program Files\Common Files\Roxio Shared\OEM\12.0\DLLShared\;C:\Program Files\Roxio\OEM\AudioCore\;C:\Program Files\Windows Live\Shared;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.6.0_23\bin;C:\apache-maven-2.2.1\bin;C:\apache-tomcat\bin;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\OpenVPNTech\bin
java.runtime.name=Java(TM) SE Runtime Environment
java.runtime.version=1.6.0_23-b05
java.specification.name=Java Platform API Specification
java.specification.vendor=Sun Microsystems Inc.
java.specification.version=1.6
java.vendor=Sun Microsystems Inc.
java.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
java.vendor.url=http://java.sun.com/
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
java.version=1.6.0_23
java.version=1.6.0_23
java.vm.info=mixed mode, sharing
java.vm.name=Java HotSpot(TM) Client VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=Sun Microsystems Inc.
java.vm.version=19.0-b09
line.separator=
os.arch=x86
os.arch=x86
os.name=Windows 7
os.version=6.1
path.separator=;
path.separator=;
sun.arch.data.model=32
sun.boot.class.path=C:\Arquivos de programas\Java\jre6\lib\resources.jar;C:\Arquivos de programas\Java\jre6\lib\rt.jar;C:\Arquivos de programas\Java\jre6\lib\sunrsasign.jar;C:\Arquivos de programas\Java\jre6\lib\jsse.jar;C:\Arquivos de programas\Java\jre6\lib\jce.jar;C:\Arquivos de programas\Java\jre6\lib\charsets.jar;C:\Arquivos de programas\Java\jre6\lib\modules\jdk.boot.jar;C:\Arquivos de programas\Java\jre6\classes
sun.boot.library.path=C:\Arquivos de programas\Java\jre6\bin
sun.cpu.endian=little
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
sun.desktop=windows
sun.io.unicode.encoding=UnicodeLittle
sun.jnu.encoding=Cp1252
sun.management.compiler=HotSpot Client Compiler
sun.os.patch.level=
user.country=BR
user.dir=C:\Area51\projetosEclipse\workspace\test
user.home=C:\Users\ricardospinoza
user.language=pt
user.name=ricardospinoza
user.timezone=
user.variant=

Referências:

About these ads

Deixe um comentário

Arquivado em Java

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s