Home > Part 4: Specifying parameters with a custom properties file
Checklist:
EMAIL THIS LICENSING & REPRINTS

Part 4: Specifying parameters with a custom properties file

15 Jul 2005

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   

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 "sap.properties" 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 com.sap.mw.jco.*;
import java.util.ResourceBundle;
...
ResourceBundle sapBundle = ResourceBundle.getBundle("sap");
    
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>

GETTING CONNECTED WITH JCO

 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


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
IT Checklists
Capacity planning checklist
How to build a business case for RFID
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
Conclusion and more resources

SAP Java / J2EE
An ABAP user wants to learn XI
Select Text fields: Case-insensitive
Finding BADIs you can use
Quiz: SAP ABAP development
Is this the quickest way to find a BADI?
Easily debug error messages in SAP processes
Is there a 'load of program' option in report generation?
Deleting entries from a dynamic table
Defining a structure in a report
Viewing a list of SAP interfaces

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


HomeNewsTopicsBlogsTipsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2000 - 2008, TechTarget | Read our Privacy Policy
SearchSAP.com is a search service provided by TechTarget and is completely
independent of and not affiliated with SAP AG.
  TechTarget - The IT Media ROI Experts