Here's the code which helps to create an Ice.Properties instance using a file that's located in a jar (or anywhere else you can get an InputStream):
Code:
import java.io.IOException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
import Ice.Util;
/**
* <p>
* <code>PropertiesUtil</code> helps create ICE {@link Ice.Properties} instances from {@link Properties}
* instances. This is useful for when you want to load ICE properties by some means other than a relative or absolute
* file path (which is all that {@link Ice.Properties#load(String)} allows), such as from a properties file stored in a
* jar.
* </p>
*
* @author Chris Bartley (bartley@cmu.edu)
*/
public final class PropertiesUtil
{
/**
* Returns a new {@link Ice.Properties} instance containing all the properties in the given {@link Properties}
* instance. If the given {@link Properties} instance is <code>null</code> or empty, this returns an empty
* {@link Ice.Properties} instance (equivalent to calling {@link Util#createProperties()}).
*/
public static Ice.Properties createIceProperties(final Properties properties)
{
final Ice.Properties iceProperties = Util.createProperties();
if (properties != null && !properties.isEmpty())
{
final Enumeration propertyNames = properties.propertyNames();
while (propertyNames.hasMoreElements())
{
final String key = (String)propertyNames.nextElement();
final String val = properties.getProperty(key);
iceProperties.setProperty(key, val);
}
}
return iceProperties;
}
private PropertiesUtil()
{
// private to prevent instantiation
}
}
Example usage:
Code:
final Properties javaProperties = new Properties();
javaProperties.load(getClass().getResourceAsStream("/com/foo/bar/config.properties"));
final Ice.Properties iceProperties = PropertiesUtil.createIceProperties(javaProperties);
enjoy!