You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Neelesh Bodas <ne...@gmail.com> on 2006/06/22 19:55:51 UTC

Logging related problems with HttpClient

Hello,

I am having problems while using HttpClient. Here is a sample code :

package src.com.example.web;
// all necessary imports
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;


public class Sample {

      private static String url = "http://www.apache.org/";

        public static void main(String[] args) {
          // Create an instance of HttpClient.
          HttpClient client = new HttpClient();

        }
}

I have made sure that following jars are in the classpath :
commons-codec-1.3.jar
commons-logging-1.1.jar
commons-logging-adapters-1.1.jar
commons-logging-api-1.1.jar
junit-4.1.jar
commons-httpclient-3.0.1.jar

[(I have made this list based on the dependency list given on HttpClient page)

I am getting the following runtime error:

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/logging/LogFactory
      at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:65)
      at src.com.example.web.Sample.main(Sample.java:12)

I have also tried using log4j but that didnot solve the problem. (As
an aside I am using Java 5.0 so I thing the logging facility provided
by java.util should be fine)

Any pointers regarding how to remove this error and get the code working?

Thanks in Advance


~Neelesh

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Logging related problems with HttpClient

Posted by Neelesh Bodas <ne...@gmail.com>.
Hi,
Thanks for the reply. My comments are inlined.

>
> You're *sure* they're in the classpath?  Can you prove it (to yourself)
> somehow?  It would seem that unless you're doing strange things with
> classloaders, you wouldn't get this error if you have
> commons-logging-1.1.jar in your classpath.
>
> Erik
>

I don't know what it exactly means to "prove" that they are in
classpath, but this is what I did :


package src.com.example.web;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.logging.*;


public class Sample {
	private static String url = "http://www.apache.org/";

	  public static void main(String[] args) {
	    // Create an instance of HttpClient.
	    //HttpClient client = new HttpClient();   // Commented out temporarily.

	    LogFactory.getLog(Sample.class); // works

	    LogFactory.getLog(HttpClient.class); // doesnot work at run time

	  }
}

I observe that the LogFactory class has no problem in getting loaded,
which means that Commons-logging might not be an issue. Also from the
error messages it appears that HttpClient class is available, but it
is *HttpClient* class which is not able to find LogFactory. So this
leaves me wondering why HttpClient class has a problem finding the
LogFactory if my Sample class doesnot?

Thanks
Neelesh

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Logging related problems with HttpClient

Posted by Erik Price <ep...@camsys.com>.
Neelesh Bodas wrote:
> I have made sure that following jars are in the classpath :
> commons-codec-1.3.jar
> commons-logging-1.1.jar
> commons-logging-adapters-1.1.jar
> commons-logging-api-1.1.jar
> junit-4.1.jar
> commons-httpclient-3.0.1.jar

You're *sure* they're in the classpath?  Can you prove it (to yourself) 
somehow?  It would seem that unless you're doing strange things with 
classloaders, you wouldn't get this error if you have 
commons-logging-1.1.jar in your classpath.

Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Logging related problems with HttpClient

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Neelesh,

> I have made sure that following jars are in the classpath :
> commons-codec-1.3.jar
> commons-logging-1.1.jar
> commons-logging-adapters-1.1.jar
> commons-logging-api-1.1.jar
> junit-4.1.jar
> commons-httpclient-3.0.1.jar

You don't need junit to run HttpClient, only to build it.

> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/apache/commons/logging/LogFactory
>       at 
org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:65)
>       at src.com.example.web.Sample.main(Sample.java:12)
> 
> Any pointers regarding how to remove this error and get the code 
working?

Being in the classpath is not enough. Find out in which
classloader the JARs are. Make sure there are no duplicates
in other classloaders along the parent chain. If HttpClient
is in a parent classloader of commons-logging, it doesn't
have access to the classes.

Also try with commons-logging 1.0.3 instead of 1.1. I don't
know whether they are binary compatible.

If nothing helps, consider asking on the commons-logging
mailing list. They should have more experience with
classloader issues.

hope that helps,
  Roland



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org