P4 for Java properties
P4 for Java uses Java properties to set various operational values for
specific IOptionsServer instances and/or for P4 for Java as a whole.
These properties are typically used for things like preferred temporary
file directory locations, application version and name information for P4 Server usage, and the location of a suitable
P4 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 P4 for Java 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 P4 for Java 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 P4 for Java-wide values that do not change over the lifetime of the P4 for Java invocation and that do not differ from one
IOptionsServerinstance to another. A typical example of such a property is thecom.perforce.p4java.tmpDirproperty, which is used by P4 for Java to get the name of the temporary directory to be used for P4 for Javatmpfiles (and which defaults tojava.io.tmpdirif not given). -
As properties passed in to an individual
IOptionsServerinstance through the server factorygetServermethod’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 P4 Server host test on port 1666 with the
P4 Server
client name test12_client and
P4 Server
user name test12 logged in automatically (note that the
login only works if the underlying authentication succeeds — see
Authentication
for details.