On 5/12/2015 12:33 PM, Steven White wrote:
> Hi Everyone,
>
> I am trying to use SolrJ to add docs to Solr.  The following line:
>
>     HttpSolrClient solrServer = new HttpSolrClient("
> http://localhost:8983/solr";);
>
> Is failing with exception:
>
>     Exception in thread "main" java.lang.NoClassDefFoundError:
> org.apache.commons.logging.LogFactory
> at
> org.apache.http.impl.client.CloseableHttpClient.<init>(CloseableHttpClient.java:60)
> at
> org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:271)
> at
> org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:127)
>     . . . . . . . . . . .
>     Caused by: java.lang.ClassNotFoundException:
> org.apache.commons.logging.LogFactory
> at java.net.URLClassLoader.findClass(URLClassLoader.java:665)
> at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:942)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:851)
>     . . . . . . . . . . .
>
> I pulled in everything from \solr-5.1.0\dist\solrj-lib and I included
> "solr-solrj-5.1.0.jar" from "\solr-5.1.0\dist".

You need to make a decision about how to do your logging.  This decision
is intentionally NOT made for you, so you can do whatever you wish.

SolrJ uses the slf4j logging API, but slf4j doesn't actually do any
logging itself, you must include jars to decide which logging framework
will actually do the logging.  In the server/lib/ext directory of the
Solr binary download, you will find a set of jars.  These jars set up
the logging intercepts that Solr (and SolrJ) will need for third-party
libraries, and configure it to bind the actual logging to log4j.

While SolrJ itself uses slf4j directly, some of the third-party
libraries use other logging frameworks, which must be intercepted by
slf4j for a consistent logging experience.  For your error message
above, it is the HttpClient library that is trying to load the Apache
Commons Logging class.  The jcl-over-slf4j jar provides an
implementation of the commons logging classes, and directs those logs
through slf4j.

You will also need the server/resources/log4j.properties file somewhere
on your classpath, or specified in a system property on your program
startup, in order to configure log4j.  You'll probably want to customize
that properties file.

If you want to use a different logging framework other than log4j for
the actual logging, you will need to research how to set up your slf4j
jars to accomplish your goal.  Some limited information can be found here:

http://wiki.apache.org/solr/SolrLogging

More comprehensive information, not specific to Solr, can be found here:

http://slf4j.org/

Thanks,
Shawn

Reply via email to