Maven2 and Properties
Maven2でjava.util.Propertiesを利用する方法。(Maven Getting Started Guideに書いてあるけど...)
src/test/resources/test.properties
foo=bar
src/test/java/example01/HelloTest.java
package example01;
import java.io.*;
import java.util.*;
import junit.framework.*;
import org.apache.commons.logging.*;
public class PropertiesTest extends TestCase
{
private static final Log log = LogFactory.getLog(PropertiesTest.class);
public void testProperties()
{
InputStream is = null;
try
{
is = this.getClass().getResourceAsStream("/test.properties");
Properties props = new Properties();
props.load(is);
String foo = props.getProperty("foo");
log.trace("foo: " + foo);
String hoge = props.getProperty("hoge");
log.trace("hoge: " + hoge);
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
if (is != null)
{
is.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
誰か教えて!
Mavenのsiteでは、application.propertiesをsrc/resources/META-INF/に置くように書いてあるけど、当方の設定では、アクセスできません。誰か教えて!