P4Java properties

P4Java uses Java properties to set various operational values for specific IOptionsServer instances and/or for P4Java as a whole. These properties are typically used for things like preferred temporary file directory locations, application version and name information for Helix Server usage, and the location of a suitable Helix Server authentication tickets file (see Authentication for details). A full list of publicly-visible properties (with default values) is given in the PropertyDefs Javadoc.

Properties intended for P4Java use can have “long form” or “short form” names. Long form names are canonical, and are always prefixed by the string represented by PropertyDefs.P4JAVA_PROP_KEY_PREFIX (normally com.perforce.p4java., for example, com.perforce.p4java.userName). Short form names are the same string without the standard prefix (for example, userName). Use long form names when there’s any chance of conflict with system or other properties; short form names, on the other hand, are convenient for putting property values onto URI strings as long as you know the property name won’t collide with another property name in use by the app or system.

Properties can be passed to P4Java in several ways:

  • As properties originally passed to the JVM using the usual Java JVM and system properties mechanisms.

    Passing properties in this way is useful for fundamental P4Java-wide values that do not change over the lifetime of the P4Java invocation and that do not differ from one IOptionsServer instance to another. A typical example of such a property is the com.perforce.p4java.tmpDir property, which is used by P4Java to get the name of the temporary directory to be used for P4Java tmp files (and which defaults to java.io.tmpdir if not given).

  • As properties passed in to an individual IOptionsServer instance through the server factory getServer method’s properties parameter.

    Properties passed in this way override properties passed in through the JVM. This mechanism is useful for any properties that are (or may be) server-specific, such as userName, clientName, and so on.

  • As properties passed in through the server factory’s URI string parameter query string.

    Properties passed in this way override properties passed in through the properties parameter and the JVM. This mechanism is useful for ad hoc property-passing and/or overriding less-changeable properties passed in through the properties parameter.

The following code shows an example of passing properties to an IOptionsServer instance using the URI string query mechanism:

IOptionsServer server = ServerFactory.getServer(
  "p4java://test:1666?userName=test12&clientName=test12_client&"
  + "autoConnect=y", null);

Assuming no errors occur along the way, this code returns an IOptionsServer object connected to the Helix Server host test on port 1666 with the Helix Server client name test12_client and Helix Server user name test12 logged in automatically (note that the login only works if the underlying authentication succeeds — see Authentication for details.