Cannot import org/apache/commons/logging/LogFactory as Plugin | Community
Skip to main content
Level 6
October 16, 2015
Solved

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

  • October 16, 2015
  • 7 replies
  • 3451 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by JustinEd3

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

7 replies

JustinEd3Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

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

Level 6
October 16, 2015

Thank you for your quick response.

 

I will uninstall and do as you say.

 

Kind Regards

Clive

Level 6
October 16, 2015

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/?$filter=CountryID+eq+"
                + 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

Adobe Employee
October 16, 2015

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?

October 16, 2015

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

Level 2
October 16, 2015

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)

smacdonald2008
Level 10
October 16, 2015

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