I want to follow up on the ClassCastException issue with custom Plugins. Turns out that the exception is not happening because an older version of Solr could be some how loaded in the classpath. I had to dig down the rabbit hole which brought me to SolrResourceLoader.
turns out that the new classLoader is created which loads all the jars from solr.war then it goes to look for custom plugins in the lib folder. addToClassLoader("./lib/", null, true); Here replaceClassLoader method is supposed to create a new classLoader that has all the packages from solr.war and the custom jars into one but that is not happening. Hence if you have a class in lib folder but are extending a class packaged into solr.war you will get a classCastException because of return clazz = Class.forName(cname, true, classLoader).asSubclass(expectedType); line 454 in findClass method My solution to this above problem was the add my custom jar in solr.war this makes sure that the same classLoader loads all the jars. That said a last year there was a patch created for 4.3 to fix the SharedLib issue. https://issues.apache.org/jira/browse/SOLR-4791 could this have broken the above scenarios of loading libraries from ./lib In any case if others are facing ClassCastExceptions try adding your library to solr.war This was the original way of combining custom libs. On Fri, May 23, 2014 at 1:27 PM, Jack Krupansky <j...@basetechnology.com> wrote: > Are you sure that you compiled your code with the proper Solr jars so that > the class signature (extends, implements, and constructors) matches the > Solr 4.7.2 jars? I mean, Java is simply complaining that your class is not > a valid value source class of the specified type. > > -- Jack Krupansky > > -----Original Message----- From: Summer Shire > Sent: Friday, May 23, 2014 12:40 PM > To: solr-user@lucene.apache.org > Subject: Solr 4.7.2 ValueSourceParser classCast exception > > > Hi All, > > I have my own popularity value source class > and I let solr know about it via solrconfig.xml > > > <valueSourceParser name="popularity" > class="mysolr.sources.PopValueSourceParser" > /> > > But then I get the following class cast exception > > I have tried to make sure there are no old Solr jar files in the classpath. > > Why would this be happening ? > > I even tried to use the lib tag to hard code the solr and solrj jars for > 4.7.2 > > org.apache.solr.common.SolrException: Error Instantiating > ValueSourceParser, mysolr.sources.PopValueSourceParser failed to > instantiate org.apache.solr.search.ValueSourceParser > at org.apache.solr.core.SolrCore.<init>(SolrCore.java:844) > at org.apache.solr.core.SolrCore.<init>(SolrCore.java:630) > at org.apache.solr.core.CoreContainer.createFromLocal( > CoreContainer.java:562) > at org.apache.solr.core.CoreContainer.create(CoreContainer.java:597) > at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:258) > at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:250) > at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) > at java.util.concurrent.FutureTask.run(FutureTask.java:138) > at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439) > at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) > at java.util.concurrent.FutureTask.run(FutureTask.java:138) > at java.util.concurrent.ThreadPoolExecutor$Worker. > runTask(ThreadPoolExecutor.java:886) > at java.util.concurrent.ThreadPoolExecutor$Worker.run( > ThreadPoolExecutor.java:908) > at java.lang.Thread.run(Thread.java:680) > Caused by: org.apache.solr.common.SolrException: Error Instantiating > ValueSourceParser, mysolr.sources.PopValueSourceParser failed to > instantiate org.apache.solr.search.ValueSourceParser > at org.apache.solr.core.SolrCore.createInstance(SolrCore.java:552) > at org.apache.solr.core.SolrCore.createInitInstance(SolrCore.java:587) > at org.apache.solr.core.SolrCore.initPlugins(SolrCore.java:2191) > at org.apache.solr.core.SolrCore.initPlugins(SolrCore.java:2185) > at org.apache.solr.core.SolrCore.initPlugins(SolrCore.java:2218) > at org.apache.solr.core.SolrCore.initValueSourceParsers( > SolrCore.java:2130) > at org.apache.solr.core.SolrCore.<init>(SolrCore.java:765) > ... 13 more > Caused by: java.lang.ClassCastException: class mysolr.sources. > PopValueSourceParser > at java.lang.Class.asSubclass(Class.java:3018) > at org.apache.solr.core.SolrResourceLoader.findClass( > SolrResourceLoader.java:454) > at org.apache.solr.core.SolrResourceLoader.findClass( > SolrResourceLoader.java:401) > at org.apache.solr.core.SolrCore.createInstance(SolrCore.java:531) > ... 19 more > MySolr[46778:5844 0] 2014/05/22 15:47:28 717.16 MB/4.09 GB ERROR > org.apache.solr.core.CoreContainer - > null:org.apache.solr.common.SolrException: > Unable to create core: core1 > at org.apache.solr.core.CoreContainer.recordAndThrow( > CoreContainer.java:989) > at org.apache.solr.core.CoreContainer.create(CoreContainer.java:606) > at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:258) > at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:250) > at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) > at java.util.concurrent.FutureTask.run(FutureTask.java:138) > at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439) > at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) > at java.util.concurrent.FutureTask.run(FutureTask.java:138) > at java.util.concurrent.ThreadPoolExecutor$Worker. > runTask(ThreadPoolExecutor.java:886) > at java.util.concurrent.ThreadPoolExecutor$Worker.run( > ThreadPoolExecutor.java:908) > at java.lang.Thread.run(Thread.java:680) > > > Thanks, > Summer >