[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.technology.equinox] Re: No suitable Log constructor error

Hi Simon,

Thank you very much for the hints. I tried 2) and 3) (unfortunately I 
couldn't drop log4j dependency, so 1) was not an option for me).

Bad news is that neither 2) and 3) worked too. However, looking into SLF4J 
pattern I had the idea to build a log4j wrapper in same way as 
jcl-over-slf4j and that finally worked. I added some code snippet below, but 
I can provide the full solution for anyone interested.

Anyway, your hints pointed me to a solution. Thanks!

Marcos


package org.apache.log4j;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Logger {

    private Log log;

    private Logger(Class clazz) {
        log = LogFactory.getLog(clazz);
    }

    private Logger(String name) {
        log = LogFactory.getLog(name);
    }

    public static Logger getLogger(Class clazz) {
        return new Logger(clazz);
    }

    public void debug(Object message) {
        System.out.println("DEBUG: " + message);
        log.debug(message);
    }

    public void debug(Object message, Throwable t) {
        System.out.println("DEBUG: " + message);
        log.debug(message, t);
    }

...

}


"Simon Kaegi" <simon_kaegi@xxxxxxxxxx> escreveu na mensagem 
news:f6j80l$p1q$1@xxxxxxxxxxxxxxxxxxxx
> Hi Marcos,
>
> Please open a bug for this - this is going to be tough to deal with.
> The problem here is that your use of log4j in your jsp is being leaked via 
> the context class loader into the jasper implementations use of commons 
> logging.
> The commons logging discovery process will find log4j on the CCL but not 
> in it's own class hierarchy and will then run into problems.
>
> I can think of two workarounds:
> 1) Remove your direct dependency on log4j from your jsp bundle and instead 
> move it to another bundle you can call from your jsp.
> 2) If you're in full control of your platform add a fragment to the 
> commons.logging bundle that imports log4j
> 3) Take a look at SLF4J and jcl-over-slf4j and create bundles to replace 
> the commons.logging bundle.
>
> HTH
> -Simon
>
> "Marcos Pereira" <marcos-luiz@xxxxxxxxx> wrote in message 
> news:f6hmf2$3dp$1@xxxxxxxxxxxxxxxxxxxx
>> Hi all.
>>
>> I have been testing the JSP Examples Bundle found at:
>> http://www.eclipse.org/equinox/server/jsp_support.php
>>
>> It works fine without changes, but when I try to add a dependency to 
>> org.apache.log4j (either as Import-Package or Require-Bundle) the error 
>> below throws out.
>>
>> Any clue about how to fix this? I checked either on this group and on 
>> Eclipse bugzilla but unfortunately I wasn't able to find a solution so 
>> far.
>>
>> org.apache.commons.logging.LogConfigurationException: 
>> org.apache.commons.logging.LogConfigurationException: No suitable Log 
>> constructor [Ljava.lang.Class;@ff2413 for 
>> org.apache.commons.logging.impl.Log4JLogger (Caused by 
>> java.lang.NoClassDefFoundError: org/apache/log4j/Category) (Caused by 
>> org.apache.commons.logging.LogConfigurationException: No suitable Log 
>> constructor [Ljava.lang.Class;@ff2413 for 
>> org.apache.commons.logging.impl.Log4JLogger (Caused by 
>> java.lang.NoClassDefFoundError: org/apache/log4j/Category))
>> at 
>> org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
>> at 
>> org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
>> at 
>> org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
>> at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
>> at 
>> org.apache.jasper.EmbeddedServletOptions.<init>(EmbeddedServletOptions.java:43)
>> at org.apache.jasper.servlet.JspServlet.init(JspServlet.java:97)
>> at org.eclipse.equinox.jsp.jasper.JspServlet.init(JspServlet.java:81)
>> at 
>> org.eclipse.equinox.http.helper.ContextPathServletAdaptor.init(ContextPathServletAdaptor.java:31)
>> at 
>> org.eclipse.equinox.http.servlet.internal.ServletRegistration.init(ServletRegistration.java:64)
>> at 
>> org.eclipse.equinox.http.servlet.internal.ProxyServlet.registerServlet(ProxyServlet.java:140)
>> at 
>> org.eclipse.equinox.http.servlet.internal.HttpServiceImpl.registerServlet(HttpServiceImpl.java:50)
>> at 
>> org.eclipse.equinox.jsp.examples.Activator$HttpServiceTracker.addingService(Activator.java:48)
>> at 
>> org.osgi.util.tracker.ServiceTracker$Tracked.trackAdding(ServiceTracker.java:1064)
>> at 
>> org.osgi.util.tracker.ServiceTracker$Tracked.trackInitialServices(ServiceTracker.java:926)
>> at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:330)
>> at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:274)
>> at org.eclipse.equinox.jsp.examples.Activator.start(Activator.java:26)
>> at 
>> org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:999)
>> at java.security.AccessController.doPrivileged(Native Method)
>> at 
>> org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:993)
>> at 
>> org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:974)
>> at 
>> org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
>> at 
>> org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:350)
>> at 
>> org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1118)
>> at 
>> org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:634)
>> at 
>> org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:508)
>> at 
>> org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:282)
>> at 
>> org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:468)
>> at 
>> org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:195)
>> at 
>> org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:297)
>> Caused by: org.apache.commons.logging.LogConfigurationException: No 
>> suitable Log constructor [Ljava.lang.Class;@ff2413 for 
>> org.apache.commons.logging.impl.Log4JLogger (Caused by 
>> java.lang.NoClassDefFoundError: org/apache/log4j/Category)
>> at 
>> org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:413)
>> at 
>> org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
>> ... 29 more
>> Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Category
>> at java.lang.Class.getDeclaredConstructors0(Native Method)
>> at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
>> at java.lang.Class.getConstructor0(Unknown Source)
>> at java.lang.Class.getConstructor(Unknown Source)
>> at 
>> org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:410)
>> ... 30 more
>>
>
>