我一直在使用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路径时,l get和exception:
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项目建立连接吗?我得到这个例外的原因是什么?
答案 0 :(得分:1)
如果您要连接到Solr(并使用SolrJ作为客户端库),那么您需要supposed to instantiate HttpSolrClient
:
String urlString = "http://localhost:8983/solr/collection1";
SolrClient solr = new HttpSolrClient(urlString);
BTW:URL中的锚点(例如#foo)仅用于客户端(例如浏览器),并不意味着(因此,通常不会)作为请求的一部分进行传输。