我一直在使用Solr版本4.10.2。我通过使用Maven(pom.xml)添加了solrj版本4.10.2

<dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-solrj</artifactId>
    <version>4.10.2</version>
        <scope>compile</scope>
</dependency>


这些是已安装的Maven依赖项:

solr-solrj-4.10.2.jar
httpclient-4.3.1.jar
httpcore-4.3.jar
httpmime-4.3.1.jar
wstx-asl-3.2.7.jar
wstx-asl-3.2.7.jar
noggit-0.5.jar


当我定义solr http路径时,我得到和异常:

Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:157)
    at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:447)
    at org.apache.solr.client.solrj.impl.HttpClientUtil.setFollowRedirects(HttpClientUtil.java:260)
    at org.apache.solr.client.solrj.impl.HttpClientConfigurer.configure(HttpClientConfigurer.java:60)
    at org.apache.solr.client.solrj.impl.HttpClientUtil.configureClient(HttpClientUtil.java:142)
    at org.apache.solr.client.solrj.impl.HttpClientUtil.createClient(HttpClientUtil.java:118)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.<init>(HttpSolrServer.java:168)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.<init>(HttpSolrServer.java:141)
    at addIndex.main(addIndex.java:10)


这是我定义Solr路径的方式:

HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr");

HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr/#/collection1");


还有另一种方法可以与Java项目建立连接吗?我得到此例外的原因是什么?

最佳答案

如果要连接到Solr(并使用SolrJ作为客户端库),则您supposed to instantiate HttpSolrClient

String urlString = "http://localhost:8983/solr/collection1";
SolrClient solr = new HttpSolrClient(urlString);


顺便说一句:URL中的锚(例如#foo)仅适用于客户端(例如浏览器),并不意味着(因此通常不会)作为请求的一部分进行传输。

08-05 19:00