Thanks Shawn,

I am now pointing solrHomeFolder to  lucene-solr-master\solr\server\solr  which 
contains the correct solr.xml file.
Tried the following two ways to create an EmbeddedSolrServer:


1.         CoreContainer corecon = 
CoreContainer.createAndLoad(Paths.get(solrHomeFolder));
           corecon.load();
           SolrClient svr = new EmbeddedSolrServer(corecon, corename);


2.   SolrClient svr = new EmbeddedSolrServer(Paths.get(solrHomeFolder), 
corename);


They both throws the same exception  (java.lang.NoClassDefFoundError: Could not 
initialize class org.apache.solr.servlet.SolrRequestParsers).
org.apache.solr.servlet.SolrRequestParsers class is present in the 
solr-core-7.0.0-SNAPSHOT.jar and this jar is present in the WEB-INF\lib folder 
(in solr server) and also included as a dependency jar in the pom.xml of the 
test project.

Here is the full stack trace of the exception:

java.lang.NoClassDefFoundError: Could not initialize class 
org.apache.solr.servlet.SolrRequestParsers
        at 
org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:112)
        at 
org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:70)
        at 
com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSolrServer(DocPhraseUpdateProcessorTest.java:141)
        at 
com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseUpdateProcessorTest.java:99)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
        at 
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
        at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
        at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at 
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
        at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


I have debugged this a bit and found that this exception is thrown on the 
following line in EmbeddedServer.class

_parser = new SolrRequestParsers(null);

Also, the coreContainer object has no cores at this point.


Wonder if I should update my code from master (it is now about two weeks old).

Thanks for any help.

Rohana


-----Original Message-----
From: Shawn Heisey [mailto:apa...@elyograg.org] 
Sent: 08 April 2016 16:46
To: solr-user@lucene.apache.org
Subject: Re: EmbeddedSolr for unit tests in Solr 6

On 4/8/2016 7:51 AM, Rohana Rajapakse wrote:
> Thanks. I know it exists, but don't know how to use it.
>
> I am trying to use EmbeddedSolrServer(Path solrHome, String 
> defaultCoreName)
>
> What should be the "solrHome"? Should it be the actual solr home (i.e. 
> lucene-solr-master\solr\server\solr) in the solr server, or can it be any 
> temporary folder?
>
> I create it with:  new EmbeddedSolrServer((new 
> File("testdata/solr")).toPath(), "tmpcore");  and get the following Exception 
> (I use solr-Solr-7.0.0):
>
> org.apache.solr.common.SolrException: Should not have found 
> solr/@persistent . Please upgrade your solr.xml: 
> https://cwiki.apache.org/confluence/display/solr/Format+of+solr.xml
>       at 
> org.apache.solr.core.SolrXmlConfig.failIfFound(SolrXmlConfig.java:167)
>       at 
> org.apache.solr.core.SolrXmlConfig.checkForIllegalConfig(SolrXmlConfig.java:149)
>       at org.apache.solr.core.SolrXmlConfig.fromConfig(SolrXmlConfig.java:61)
>       at 
> org.apache.solr.core.SolrXmlConfig.fromInputStream(SolrXmlConfig.java:129)
>       at org.apache.solr.core.SolrXmlConfig.fromFile(SolrXmlConfig.java:111)
>       at 
> org.apache.solr.core.SolrXmlConfig.fromSolrHome(SolrXmlConfig.java:139)
>       at 
> org.apache.solr.core.SolrXmlConfig.fromSolrHome(SolrXmlConfig.java:144)
>       at 
> org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.<init>(EmbeddedSolrServer.java:70)
>       at 
> com.gossinteractive.solr.DocPhraseUpdateProcessorTest.createEmbeddedSolrServer(DocPhraseUpdateProcessorTest.java:140)
>       at 
> com.gossinteractive.solr.DocPhraseUpdateProcessorTest.setUp(DocPhraseU
> pdateProcessorTest.java:98)

You said you were using EmbeddedSolrServer with 4.x, so I assumed you knew what 
you were doing.

You are getting that Exception because the solr home you pointed to contains a 
solr.xml file in the old solr.xml format.  This format is supported by all of 
4.x, but support was dropped in 5.0.  The message is pretty clear -- it says 
that you need to upgrade your solr.xml, and even points at some documentation.  
Here's a wiki page about the old format, with a link to another page about the 
new format:

http://wiki.apache.org/solr/Solr.xml%20%28supported%20through%204.x%29

Suggestion: Rather than create a File object and convert it to a Path, use NIO2 
methods directly:

Paths.get("testdata/solr")

Thanks,
Shawn



Registered Office: 24 Darklake View, Estover, Plymouth, PL6 7TL.
Company Registration No: 3553908

This email contains proprietary information, some or all of which may be 
legally privileged. It is for the intended recipient only. If an addressing or 
transmission error has misdirected this email, please notify the author by 
replying to this email. If you are not the intended recipient you may not use, 
disclose, distribute, copy, print or rely on this email.

Email transmission cannot be guaranteed to be secure or error free, as 
information may be intercepted, corrupted, lost, destroyed, arrive late or 
incomplete or contain viruses. This email and any files attached to it have 
been checked with virus detection software before transmission. You should 
nonetheless carry out your own virus check before opening any attachment. GOSS 
Interactive Ltd accepts no liability for any loss or damage that may be caused 
by software viruses.


Reply via email to