Part 4: Specifying parameters with a custom properties file

Using a Properties file provides a good way to centralize system parameters in a single, maintainable format. However, there are some limitations to the properties file, including the fact that the fully qualified filesystem path name must be passed in order to ensure that the JVM can find the file.

In addition, using the createClient(Properties) method requires you to use the naming standard set forth in the JCo API for all name/value pairs. Although a minor inconvenience, the inability to create new name attributes may frustrate developers who adhere to an existing naming convention. Both these challenges can be overcome by creating a custom properties file that is read as a ResourceBundle within your Java application.

The ResourceBundle class allows you to specify a standard properties file (for this example I am using the "" created previously), then selectively retrieve values within your application. The distinct advantage to using a ResourceBundle is that the properties file must simply exist somewhere in your applications CLASSPATH in order for the application to find it. The idea of using the CLASSPATH becomes important when you want to package and deploy your application within a Java application server using a JAR, WAR, or EAR format.

For this example, I have combined the ResourceBundle with the String array technique detailed previously:

import java.util.ResourceBundle;
ResourceBundle sapBundle = ResourceBundle.getBundle("sap");

    Requires Free Membership to View

String[][] sapParams = { {"client", sapBundle.getString("jco.client.client")}, {"user", sapBundle.getString("jco.client.user")}, {"passwd", sapBundle.getString("jco.client.passwd")}, {"lang", sapBundle.getString("jco.client.lang")}, {"ashost", sapBundle.getString("jco.client.ashost")}, {"sysnr", sapBundle.getString("jco.client.sysnr")} {"trace", sapBundle.getString("jco.client.trace")}}; JCO.Client connection = JCO.createClient(sapParams); ... connection.disconnect();
Notice that I did not need to specify the ".properties" extension. The ResourceBundle.getBundle() method assumes (and requires) that your properties file be tagged with the ".properties" extension, and thus, you do not need to specify it.

In this instance, I chose the String array method because I needed to pass the RFC trace parameter. You could also use the ResourceBundle technique with the basic connection method by passing each parameter as a String to createClient(). The ResourceBundle technique also lets you set system parameters dynamically rather than reading them from the properties file. Simply specify the parameter directly through your application, within the String array.

In order for your application to work with a ResourceBundle you must ensure that the CLASSPATH variable contains a pointer to the directory in which the properties file is located. From a Windows console, that command would look like this:

set CLASSPATH=%CLASSPATH%;<pathname to properties file>


 Home: Introduction
 Part 1: Specifying parameters as single String values
 Part 2: Specifying parameters using a String array
 Part 3: Specifying parameters using an external properties file
 Part 4: Specifying parameters with a custom properties file
 Review: Conclusion and more resources

This was first published in July 2005

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: