Solrj - 由于 HTTPSolrServer 无法从最终 class 错误继承

Solrj - cannot inherit from final class error due to HTTPSolrServer

我一直在使用 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.access0(URLClassLoader.java:71)
    at java.net.URLClassLoader.run(URLClassLoader.java:361)
    at java.net.URLClassLoader.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)仅适用于客户端(例如浏览器),并不意味着(因此通常不会)作为请求的一部分进行传输。