<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sheila&#039;s Blog &#187; java</title>
	<atom:link href="http://sheilapollard.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://sheilapollard.com</link>
	<description>Software Development</description>
	<lastBuildDate>Wed, 24 Mar 2010 17:19:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Loading a properties file in a java web app</title>
		<link>http://sheilapollard.com/2009/03/31/loading-a-properties-file-in-a-java-web-app/?utm_campaign=feed&utm_medium=feed&utm_source=blog</link>
		<comments>http://sheilapollard.com/2009/03/31/loading-a-properties-file-in-a-java-web-app/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 11:00:23 +0000</pubDate>
		<dc:creator>Sheila</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[properties]]></category>

		<guid isPermaLink="false">http://sheilapollard.wordpress.com/?p=222</guid>
		<description><![CDATA[You&#8217;ll often want to configure parameters in a properties file and read this into a class.
config.properties:
value.a=orange
value.b=apple
If you&#8217;re simply loading a file in a java program you can use:
Properties props = new Properties();
props.load(new FileInputStream("config.properties"));
String value = props.getProperty("value.a");
But when loading a property file in a web application you should package the file in your deployed archive and [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ll often want to configure parameters in a properties file and read this into a class.</p>
<p>config.properties:
<code>value.a=orange
value.b=apple</code></p>
<p>If you&#8217;re simply loading a file in a java program you can use:
<code>Properties props = new Properties();
props.load(new FileInputStream("config.properties"));
String value = props.getProperty("value.a");</code></p>
<p>But when loading a property file in a web application you should package the file in your deployed archive and load the file from the classpath.  This avoids problems with loading files from different locations on a file system.</p>
<p>build.xml: gen-jar-files target
<code>&lt;copy todir="${jar.dir}"&gt;
  &lt;fileset dir="${resources.dir}"&gt;
    &lt;include name="*.properties" /&gt;
  &lt;/fileset&gt;
&lt;/copy&gt;</code></p>
<p>This takes any properties files in the resources.dir and copies them into the jar file.  Now you can access the file within your application from the classpath:
<code>ClassLoader cl = this.getClass().getClassLoader();
InputStream is = cl.getResourceAsStream("config.properties");
Properties configProperties  = new Properties();
try {
  configProperties.load(is);
  String valueA = configProperties.getProperty("value.a");
} catch (IOException e) {
  e.printStackTrace();
}</code></p>
<br /><a href="http://sheilapollard.com/wp-content/plugins/feed-statistics.php?url=aHR0cDovL3NoZWlsYXBvbGxhcmQud29yZHByZXNzLmNvbS8/cD0yMjIjY29tbWVudHM=" title=\"Comments on &quot;Loading a properties file in a java web app&quot;\"><img src="http://sheilapollard.com/wp-content/plugins/feed-comments-number/image.php?222" alt="Comments" /></a> <img src="http://sheilapollard.com/wp-content/plugins/feed-statistics.php?view=1&post_id=222" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://sheilapollard.com/2009/03/31/loading-a-properties-file-in-a-java-web-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
