I am currently working on a custom DataImportHandler for Solr 8.4.1.
I wrote my own entity processor class where I used the json-path library. And even though the solr-dataimporthandler (which I have to import in my custom class) seems to already have a json-path dependency on itself, I wanted to go the safe way and compiled all necessary classes into the OparlEntityProccessor.jar.
However, when I execute the dataimporter via the web interface, I get this Error:
Exception in thread "Thread-16" java.lang.NoClassDefFoundError: net/minidev/json/writer/JsonReaderI
at com.jayway.jsonpath.internal.DefaultsImpl.<init>(DefaultsImpl.java:17)
at com.jayway.jsonpath.internal.DefaultsImpl.<clinit>(DefaultsImpl.java:15)
at com.jayway.jsonpath.Configuration.getEffectiveDefaults(Configuration.java:48)
at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:173)
at com.jayway.jsonpath.internal.ParseContextImpl.<init>(ParseContextImpl.java:21)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:599)
at com.github.fbecker97.OparlEntityProcessor.initOparlObjects(OparlEntityProcessor.java:55)
at com.github.fbecker97.OparlEntityProcessor.init(OparlEntityProcessor.java:33)
at org.apache.solr.handler.dataimport.EntityProcessorWrapper.init(EntityProcessorWrapper.java:77)
at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:434)
at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:415)
at org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:330)
at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:233)
at org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:424)
at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:483)
at org.apache.solr.handler.dataimport.DataImporter.lambda$runAsync$0(DataImporter.java:466)
at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.ClassNotFoundException: net.minidev.json.writer.JsonReaderI
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:436)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:555)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 17 more
The jar is located at C:...\solr-8.4.1\server\solr\maincore\lib and the important part of my solrconfig.xml looks like this:
<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">custom-import-config.xml</str>
</lst>
</requestHandler>
with this custom-import-config.xml:
<dataConfig>
<dataSource type="URLDataSource"
connectionTimeout="3000"
readTimeout="5000"
baseUrl="..."/>
<document>
<entity name="oparl"
processor="com.github.fbecker97.OparlEntityProcessor"
transformer="LogTransformer"
logTemplate="TEST: ${oparl.id}" logLevel="error" >
</entity>
</document>
</dataConfig>
... is that solr definitely finds the jar and executes the class, otherwise the error would be different. It even says in the log file that 1 lib has been added to the classloader. I also looked into the jar to make sure it includes the "missing" net.minidev.json.writer.JsonReaderI class, and it does. So.. why doesn't solr find it when executing the importer?
There's another strange thing I found, even though it technically shouldn't matter: Like I said before, solr and the solr-dataimporthandler already have a com.jayway.jsonpath dependency, which made me wonder why I even had to include these dependencies in my jar in the first place. But then I found this in solr/core/build.gradle:
implementation('com.jayway.jsonpath:json-path', {
exclude group: "net.minidev", module: "json-smart"
I don't know much about gradle, but they seem to exclude the crucial classes I need from their dependencies. Then again, Im not sure how this would matter as I explicitly compiled all needed classes into my jar.
Is anyone familiar with this kind of problem ?
EDIT:
I now wrote another small proccessor class for testing purposes and I included some stuff from another external library called ejml. Solr itself doesn't have any dependencies on this library so just like before I compiled all neccessary classes into the jar.
This time solr was able to execute the proccessor flawlessly.
This makes me think that there really is some weird stuff going on with the json-path dependency and the above mentioned exclusion of json-smart.
Solved it!
I deleted the json-path-2.4.0.jar from ...\solr-8.4.1\server\solr-webapp\webapp\WEB-INF\lib. That way solr has no other option than searching for the missing classes in my jar.. i guess ? I still don't really know what's going on there, but it works so...