2
我正在通過擴展SearchComponent類來編寫solr插件。我的新課程是a.jar歸檔的一部分。我的課也取決於jar b.jar。我將兩個jar放在我的core/lib文件夾中,然後在solrconfig.xml中聲明我的新組件。該組件被正確調用,直到b.jar中的類ClassFromB嘗試從classpath加載類路徑資源stopwords.txt。Solr插件類加載器
的一塊類ClassFromB代碼如下所示:
...
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource("stopwords.txt"); //with cl.getResource("/stopwords.txt"); I get the same exception
String content = IOUtils.toString(curl.openConnection().getInputStream());
...
上面最後一行拋出一個NPE告訴我,資源沒有找到。 因此,類ClassFromB被加載,因爲它執行代碼直到失敗的最後一行。此外,我再次檢查b.jar,並可以在根目錄中查看stopwords.txt文件。
我該怎麼做才能從類ClassFromB中看到該資源?
如何包命名,其中stopWords.txt中居住?您是否嘗試用「絕對路徑」來解決文件? – cheffe 2014-09-05 11:17:06
該類的FQN是com.sxxxx.solr.ClassFromB。文件synonyms synonyms .txt文件位於默認軟件包中(位於b.jar文件夾中)。 – biliboc 2014-09-05 15:17:56
您是否找到解決這個老問題的方法? – Klaus 2016-03-29 20:51:54