System properties can be specified to configure various aspects of the AS/400 Toolbox for Java. For example, you can use system properties to define a proxy server or a level of tracing. System properties are useful for convenient runtime configuration without needing to recompile code. System properties work like environment variables. If a system property is changed during runtime, the change will generally not be reflected until the next time the application is run.
There are several ways to set system properties:
System properties can be set programmatically using the java.lang.System.setProperties() method.
For example, to set the com.ibm.as400.access.AS400.proxyServer
property set to hqoffice
:
Properties systemProperties = new Properties (); systemProperties.put ("com.ibm.as400.access.AS400.proxyServer", "hqoffice"); System.setProperties (systemProperties);
Many environments allow the user to set system properties easily when running applications from a command line. Specify system properties using the -D option of the java command.
For example, to run the application called Inventory with the
com.ibm.as400.access.AS400.proxyServer
property set to
hqoffice
:
java -Dcom.ibm.as400.access.AS400.proxyServer=hqoffice Inventory
In some environments, it may be inconvenient to instruct all users to set their own system properties. As an alternative, AS/400 Toolbox for Java system properties can be specified in a file called jt400.properties which will be searched for as if it were part of the com.ibm.as400.access package. In other words, it should be located in a com/ibm/as400/access directory that is pointed to by the classpath.
For example, to set the com.ibm.as400.access.AS400.proxyServer
property to hqoffice
, make sure the jt400.properties file contains
the following line:
com.ibm.as400.access.AS400.proxyServer=hqoffice
Backslashes work as escape characters in properties files. If you need to specify an actual backslash, use two backslashes.
Modify this sample of a
jt400.properties file for your environment.
Some browsers do not load properties files without explicitly changing security settings. However, most browsers do allow properties in .class files, so AS/400 Toolbox for Java system properties can also be specified by a class called com.ibm.as400.access.Properties which extends java.util.Properties.
For example, to set the com.ibm.as400.access.AS400.proxyServer
property to hqoffice
, use the following Java code:
package com.ibm.as400.access; public class Properties extends java.util.Properties { public Properties () { put ("com.ibm.as400.access.AS400.proxyServer", "hqoffice"); } }
Modify and compile this sample of a
Properties.java source file for your environment.
If an AS/400 Toolbox for Java system property is set using more than one of the mechanisms described above, then the precedence is as follows (in order of decreasing precedence):
The following system properties are supported by the AS/400 Toolbox for Java:
Property name | Description |
---|---|
Proxy server properties | |
"com.ibm.as400.access.AS400.proxyServer" | Specifies the proxy server host name and port number,
specified in the format: hostName:portNumberThe port number is optional. |
Trace properties | |
"com.ibm.as400.access.Trace.category" | Specifies which trace categories to enable. This is a comma-delimited list containing any combination of trace categories. The complete list of trace categories is defined in the Trace class. |
"com.ibm.as400.access.Trace.file" | Specifies the file to which trace output is written. The default is to write trace output to System.out. |