在 Nutch 中为自定义插件添加属性文件

Add properties file for custom plugin in Nutch

我是 Nutch 的初学者。我已经完成了爬行,根据不同的教程创建了一个自定义插件。对于特定任务,我的 Java class 必须为某些任务使用名为 sample.properties 的属性文件。我在以下代码中收到 NullPointerException

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

我不知道把这个属性文件放在哪里,因为用ant编译后它没有移动到编译的jar中。目前我放置在 java class 的同一目录中。任何帮助将不胜感激。

我刚刚通过在插件的 build.xml 中添加一个复制任务来解决:

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

它将属性文件复制到已编译的 jar 中,问题已解决。干杯!!

编辑:

我刚刚也用了另一种方法。将属性文件移动到 conf 目录并通过

在 Parsefilter 中获取输入
Properties property = new Properties();
InputStream input = ClassLoader.getSystemResourceAsStream("sample.properties");
property.load(input);