Date Created: Wed 02-Jan-2008

Related Document Categories:



    Simple properties manager class to get Java properties from a Java property file.

    /*

    how to use the PropertiesManager class

    ProfileManager pm = new ProfileManager();
    PropertiesManager propman = new PropertiesManager();
    String profileBase = propman.getProperty("logview.properties","profiles.root");
    String logFolder = propman.getProperty("logview.properties","log.folder");

    */

    /*
    * Created on 09-Nov-2007
    *
    */
    package com.websphere.utils;

    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;

    /**
    * @author Steven Charles Robinson - November - 2007
    *
    */
    public class PropertiesManager {

    /**
    *
    */
    public PropertiesManager() {
    super();
    // TODO Auto-generated constructor stub
    }

    public String getProperty(String propertyFile,String propertyName)
    {
    Properties props = null;
    // Get the properties file from the classpath
    try{
    props = getPropertiesFromClasspath(propertyFile);
    }catch(Exception e){
    System.out.println(e.getMessage());
    }
    return props.getProperty(propertyName);

    }

    private Properties getPropertiesFromClasspath(String propFileName) throws IOException {
    Properties props = new Properties();
    InputStream inputStream = this.getClass().getResourceAsStream(propFileName);

    if (inputStream == null) {
    throw new FileNotFoundException("property file '" + propFileName
    + "' not found in the classpath");
    }

    props.load(inputStream);

    return props;
    }

    }

Middleware Mentor - Steven Charles Robinson

About Me

Steve Robinson has been working in IT for over 15 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware consulting. Steve comes from both an administration and development background.

Before moving to JEE, Steve was an accomplished developer and consultant for both IBM Lotus Notes and Microsoft .NET Technologies.

Follow Steve as @stevencrobinson on twitter.

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Oracle WebLogic Categories

JBoss Categories

Other Categories