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

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
Integrating Java apps and SAP with the JCo API -- resources

SAP Java and J2EE
SAP CTO Sikka: SAP's innovation gets overlooked
SAP CTO expects today's SAP applications to be running in 2020
Tips on SAP ABAP
How to provide an SAP R/3 4.5B application server with a Web service interface
Consuming a Web service from an SAP 4.6c R/3 application server
SAP NetWeaver Configuration and Customization
Is C, C++ and Java knowledge required when learning SAP?
How to be a self-taught NetWeaver and ABAP expert
Getting started with a NetWeaver career
An ABAP user wants to learn XI

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




SAP Exchange Infrastructure (XI) Research Papers
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, 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