Abhishek Abhishek - 2 months ago 13
Java Question

Add properties file for custom plugin in Nutch

I'm a beginner in Nutch. I have done crawling, created a custom plugin based on different tutorials. For a particular task, my Java class have to use a properties file named

sample.properties
for some tasks. I've getting a NullPointerException on the following code.

Properties property = new Properties();
InputStream input = getClass().getResourceAsStream("sample.properties");
property.load(input);


I don't know where to place this properties file, because it doesn't moves to the compiled jar after compiling with ant. Currently I'm placing at the same directory of java class. Any help will be appreciated.

Answer

I just solved by adding a copy task in plugin's build.xml as :

<copy todir="${build.classes}">
    <fileset dir="${src.dir}" includes="**/*.properties"/>
</copy>

It copies the properties file to the compiled jar and issue was solved. Cheers !!

EDIT :

I just used another method also. Moved the properties file to conf directory and get the input in Parsefilter by,

Properties property = new Properties();
InputStream input = ClassLoader.getSystemResourceAsStream("sample.properties");
property.load(input);