Personal tools
You are here: Home Maven Notes Maven2 and Properties
Document Actions

Maven2 and Properties

by MIYACHI Yasuhiko last modified 2006-06-22 16:12

Maven2java.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/に置くように書いてあるけど、当方の設定では、アクセスできません。誰か教えて!


Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: