VIEWING THE JVM SYSTEM PROPERTIES When testing an application, you often need to know exactly what input is being passed to the JVM from the operating system. Is there a timezone being set, is daylight savings on (a notable JVM bug on Windows NT), what directory is it saying is the user's home directory? Fortunately this is very easy to test. The operating system's properties are accessible via the System.getProperties() method. Note that this is not a direct access to the environment properties by typing the 'set' command on a command line in UNIX and Windows, but instead it provides access to a standard set of properties for Java, to any vendor extras and to anything passed into the Java command via the -D flag. The following is simple code to show these properties: import java.util.Properties; public class SysPropDump { static public void main(String[] args) { System.getProperties().list(System.out); } } This works well for properties with short values, such as: java.vendor=Apple Computer, Inc. but when the value is long, it will get cut off, for example with the classpath: java.class.path=/System/Library/ Frameworks/JavaVM.fra... To show all data, the SysPropDump class needs to, on its own, do the printing of each value in the Properties object. However this is still a simple proccess: import java.util.Properties; import java.util.Enumeration; /** * Invoke with either: java SysPropDump for a quick list or * java SysPropDump -v for a verbose list. */ public class SysPropDump { static public void main(String[] args) { Properties props = System.getProperties(); if( (args.length > 0) && "-v".equals(args[0]) ) { // print each property out, one at a time Enumeration names = props.propertyNames(); System.out.println("-- listing verbose properties --"); while(names.hasMoreElements()) { String name = names.nextElement(); System.out.print(name); System.out.print("="); System.out.println(props. getProperty(name)); } } else { System.getProperties(). list(System.out); } } } java.class.path is now printed as the far spammier: java.class.path=/System/Library/Frameworks/ JavaVM.framework/Versions/1.3/Classes/ classes.jar:/System/Library/Frameworks/ JavaVM.framework/Versions/1.3/Classes/ ui.jar:.:/usr/local/javalib/BZip2.jar:/ usr/local/javalib/gnu-regexp-1.0.8.jar:/ usr/local/javalib/jdbc.jar:/ usr/local/javalib/jndi.jar:/usr/local/ javalib/jstyle.jar:/usr/local/javalib/ servlet.jar:/usr/local/javalib/tar. jar:/usr/local/javalib/xerces.jar Obviously this simple command line class can be taken further to incorporate specification of the desired properties as arguments, sorting the list by some logic, and outputting in other formats--XML, HTML, and CSV all spring to mind. Though the code is longer and more complex, it's stronger and will not leave file handles and sql connections hanging around. ----------------------------------------