Plugins Solr插件类加载器
我正在通过扩展SearchComponent类编写一个solr插件。我的新类是.jar存档的一部分。我的类也依赖于jar b.jar。我将两个JAR都放在core/lib文件夹中,并在solrconfig.xml中声明了我的新组件。该组件被正确调用,直到b.jar中的ClassFromB类尝试从classpath加载类路径资源stopwords.txt为止 ClassFromB类中的代码如下所示:Plugins Solr插件类加载器,plugins,solr,classloader,Plugins,Solr,Classloader,我正在通过扩展SearchComponent类编写一个solr插件。我的新类是.jar存档的一部分。我的类也依赖于jar b.jar。我将两个JAR都放在core/lib文件夹中,并在solrconfig.xml中声明了我的新组件。该组件被正确调用,直到b.jar中的ClassFromB类尝试从classpath加载类路径资源stopwords.txt为止 ClassFromB类中的代码如下所示: 。。。 ClassLoader cl=Thread.currentThread().getCont
。。。
ClassLoader cl=Thread.currentThread().getContextClassLoader();
URL=cl.getResource(“stopwords.txt”)//使用cl.getResource(“/stopwords.txt”);我也有同样的例外
String content=IOUtils.toString(curl.openConnection().getInputStream());
...
上面的最后一行抛出一个NPE,告诉我找不到资源。
因此,类ClassFromB被加载,因为它可以执行代码直到最后一行失败。我还仔细检查了b.jar,我可以在根目录中看到stopwords.txt文件
我应该怎么做才能看到ClassFromB类中的资源呢?但是这是可行的:
public final class Stopwords {
static {
URL curl = Stopwords.class.getClassLoader().getResource("stopwords.txt");
....
}
....
}
包的名称如何,stopwords.txt驻留在哪里?您是否尝试使用文件的“绝对路径”来寻址该文件?该类的FQN为com.sxxx.solr.ClassFromB。文件synonyms.txt位于默认包(就在b.jar归档文件中)中。您找到解决这个老问题的方法了吗?