Expand my Community achievements bar.

SOLVED

Cannot import org/apache/commons/logging/LogFactory as Plugin

Avatar

Level 6

In my bundle whenever a log is created, for example on 

DefaultHttpClient httpClient = new DefaultHttpClient();

I get org.apache.sling.api.scripting.ScriptEvaluationException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

I have created a bundle from commons-logging-1.2.jar. But I still get the NoClassDefFoundError  org/apache/commons/logging/LogFactory

This is the bundle information

CustomLoggerCustomLogger

 

 

                                     
Symbolic NameCustomLogger
Version1.0.0
Bundle Locationinputstream:CustomLogger_1.0.0.jar
Last ModificationThu Oct 30 12:48:18 CAT 2014
Start Level20
Bundle Classpath.
Exported Packagesorg.apache.commons.logging.impl,version=0.0.0
Imported Packagesorg.apache.commons.logging,version=1.1.1 from jcl.over.slf4j (2)
Manifest HeadersBundle-ClassPath: .
Bundle-ManifestVersion: 2
Bundle-Name: CustomLogger
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-SymbolicName: CustomLogger
Bundle-Version: 1.0.0
Export-Package: org.apache.commons.logging, org.apache.commons.logging.impl
Import-Package: org.apache.commons.logging
Manifest-Version: 1.0

 

Regards

 

Clive

1 Accepted Solution

Avatar

Correct answer by
Employee

Commons Logging is supported out of the box (it is actually one of 6 different Logging APIs supported). You should not deploy Commons Logging separately. That will only make things confusing. You should uninstall that bundle you created ASAP.

The problem would appear to be that the bundle which includes DefaultHttpClient isn't importing org.apache.commons.logging.

Justin

View solution in original post

7 Replies

Avatar

Correct answer by
Employee

Commons Logging is supported out of the box (it is actually one of 6 different Logging APIs supported). You should not deploy Commons Logging separately. That will only make things confusing. You should uninstall that bundle you created ASAP.

The problem would appear to be that the bundle which includes DefaultHttpClient isn't importing org.apache.commons.logging.

Justin

Avatar

Level 6

Thank you for your quick response.

 

I will uninstall and do as you say.

 

Kind Regards

Clive

Avatar

Level 6

I have done as above. I also place 

protected final Logger log = LoggerFactory.getLogger(this.getClass());

 

Inside my class and

 

    public FetchStores(Integer countryId) throws Exception {
        url = "http://externalservices.shopriteholdings.co.za/production/legacy/storelocator/datarite/Locations/?$f..."
                + countryId + "&$format=json";
        fetchStore();
    }

    private String getConnection() throws IOException, IOException {
        String output = "";
        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
        } catch (Exception e) {
            log.info("CQ ERROR: "+e.getMessage()); 
        }

 

But on DefaultHttpClient httpClient = new DefaultHttpClient(); I get 

org.apache.sling.api.SlingException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

Avatar

Employee

What versions of the httpclient and httpcore bundles have you deployed? Can you confirm that you are *not* embedding these libraries and instead using the bundles?

Avatar

Level 1

I am also facing same issue, I am using 4.1 version of httpclient and httpcore. 

Avatar

Level 2

I am seeing this same issue.  My servlet can log fine.  However, within HTTPClient those classes are trying to log and failing with below error:

I have built OSGI fragment with HTTP client and deploy to AEM OSGI bundles.  I have tried a few versions of HttpClient, but all are hitting the same error.

Please help?  Any ideas?

 

01.05.2015 16:15:54.294 *ERROR* [0:0:0:0:0:0:0:1 [1430514954291] GET /bin/VOTServlet HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

    at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:182)

    at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:150)

    at com.gm.oc.aem.oc_aem.core.impl.servlets.VOTServlet.postAccessToken2(VOTServlet.java:139)

    at com.gm.oc.aem.oc_aem.core.impl.servlets.VOTServlet.doGet(VOTServlet.java:109)

Avatar

Level 10

Writing to the AEM log file from an OSGi bundle can be done using org.slf4j.Logger and org.slf4j.LoggerFactory Java packages. See this community article where output from the OSGi is written in the log file:

http://helpx.adobe.com/experience-manager/using/developing-aem-osgi-bundles-jackrabbit.html