Thanks. I should have googled first. I came across: http://www.nabble.com/EmbeddedSolrServer-API-usage-td19778623.html
For reference, my code is now: final File dir = FileUtils.createTmpSubdir(); System.setProperty("solr.solr.home", dir.getAbsolutePath()); final File conf = new File(dir, "conf"); conf.mkdir(); final PathMatchingResourcePatternResolver pmrpr = new PathMatchingResourcePatternResolver(); final File c1 = pmrpr.getResource("classpath:test_protwords.txt").getFile(); final File c2 = pmrpr.getResource("classpath:test_stopwords.txt").getFile(); final File c3 = pmrpr.getResource("classpath:test_synonyms.txt").getFile(); final File c4 = pmrpr.getResource("classpath:test_elevate.xml").getFile(); copyAndRenameTestFile(c1, dir, "protwords.txt", conf); copyAndRenameTestFile(c2, dir, "stopwords.txt", conf); copyAndRenameTestFile(c3, dir, "synonyms.txt", conf); copyAndRenameTestFile(c4, dir, "elevate.xml", conf); final File config = pmrpr.getResource("classpath:solrconfig.xml").getFile(); final CoreContainer cc = new CoreContainer(); final SolrConfig sc = new SolrConfig(config.getAbsolutePath()); final CoreDescriptor cd = new CoreDescriptor(cc, "core0", dir.getAbsolutePath()); final SolrCore core0 = cc.create(cd); cc.register("core0", core0, false); final EmbeddedSolrServer server = new EmbeddedSolrServer(cc, "core0"); Reuben On Mon, Jul 13, 2009 at 5:00 PM, Mark Miller <markrmil...@gmail.com> wrote: > I believe that constructor expects to find an alternate format solr config > that specifies the cores, eg like the one you can find in > example/multicore/solr.xml > > http://svn.apache.org/repos/asf/lucene/solr/trunk/example/multicore/solr.xml > > Looks like that error is not finding the root solr node, so likely your > trying to use a regular solrconfig.xml format? > > -- > -- > - Mark > > http://www.lucidimagination.com > > On Mon, Jul 13, 2009 at 8:53 PM, Reuben Firmin <reub...@benetech.org> > wrote: > > > Hi, > > > > I'm setting up an embedded solr server from a unit test (the non-bolded > > lines are just moving test resources to a tmp directory which is acting > as > > solor.home.) > > > > final File dir = FileUtils.createTmpSubdir(); > > * System.setProperty("solr.solr.home", dir.getAbsolutePath());* > > final File conf = new File(dir, "conf"); > > conf.mkdir(); > > final PathMatchingResourcePatternResolver pmrpr = new > > PathMatchingResourcePatternResolver(); > > final File c1 = > pmrpr.getResource("classpath:schema.xml").getFile(); > > final File c2 = > > pmrpr.getResource("classpath:solrconfig.xml").getFile(); > > final File c3 = > > pmrpr.getResource("classpath:test_protwords.txt").getFile(); > > final File c4 = > > pmrpr.getResource("classpath:test_stopwords.txt").getFile(); > > final File c5 = > > pmrpr.getResource("classpath:test_synonyms.txt").getFile(); > > FileUtils.copyFileToDirectory(c1, conf); > > // NOTE! this lives in the top level dir > > FileUtils.copyFileToDirectory(c2, dir); > > copyAndRenameTestFile(c3, dir, "protwords.txt", conf); > > copyAndRenameTestFile(c4, dir, "stopwords.txt", conf); > > copyAndRenameTestFile(c5, dir, "synonyms.txt", conf); > > > > * final CoreContainer.Initializer initializer = new > > CoreContainer.Initializer(); > > initializer.setSolrConfigFilename("solrconfig.xml"); > > final CoreContainer coreContainer = initializer.initialize(); > > final EmbeddedSolrServer server = new > > EmbeddedSolrServer(coreContainer, ""); > > engine.setServer(server);* > > > > The problem with this is that CoreContainer trips over and dumps an > > exception to the log: > > > > javax.xml.transform.TransformerException: Unable to evaluate expression > > using this context > > at com.sun.org.apache.xpath.internal.XPath.execute(XPath.java:363) > > at > > com.sun.org.apache.xpath.internal.jaxp.XPathImpl.eval(XPathImpl.java:213) > > at > > > > > com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:275) > > at > > org.apache.solr.core.CoreContainer.readProperties(CoreContainer.java:241) > > at org.apache.solr.core.CoreContainer.load(CoreContainer.java:189) > > at > > > > > org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:104) > > at > > > > > org.bookshare.search.solr.SolrSearchEngineTest.setup(SolrSearchEngineTest.java:44) > > > > It appears to be trying to evaluate "property", which doesn't exist in > > solrconfig.xml (which is pretty much the same as > > > > > http://svn.apache.org/repos/asf/lucene/solr/trunk/example/solr/conf/solrconfig.xml > > ). > > > > > > Anybody see anything obviously wrong? If not, what else can I give you to > > help debug this? > > > > Thanks > > Reuben > > >