You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Guillaume Nodet <gn...@gmail.com> on 2008/01/25 20:07:14 UTC

Small patch to remove a hard dependency on log4j

I've raised a JIRA and attached a small patch to remove a hard dependency on
log4j.
Please, review
   https://issues.apache.org/jira/browse/OPENEJB-748

-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Small patch to remove a hard dependency on log4j

Posted by Guillaume Nodet <gn...@gmail.com>.
Actuallly the trick might me something else.  I've run into the same
problem this week and what i found is that the NoClassDefFoundError is
thrown when the JVM tries to use a class with a missing import
statement.   What i did to work around the problem is to use an inner
class:
  http://svn.apache.org/repos/asf/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
The inner class is OsgiUtil and is only called when we are sure that
OSGi is there (by checking the existence of a method earlier), so in
this case, i don't need to catch the NoClassDeffoundError.   But
before using an inner classs which uses the osgi package, the method
was in the main class and it was throwing an error when used in non
OSGi.

Not sure if I'm very clear, but in short, you need to move your
dependency in another class and try to use that class inside a
try/catch block and it should work.

On Thu, Jun 19, 2008 at 2:34 AM, David Blevins <da...@visi.com> wrote:
> I'm trying your trick out on the SXC JAXBContextImpl.  The goal is that it
> can be optional.  For some reason I cannot get it to work in any way
> whatsoever.  Wonder if you have any insight or see something I'm missing.
>
>  http://people.apache.org/~dblevins/JAXBContextFactory.java
>
> I'm testing this by marking the "sxc-jaxb" dep as "provided" in openejb-jee,
> thus ensuring it's *not* available in openejb-core at test time.  I just
> keep getting smacked in the face with a NoClassDefError:
>
> java.lang.NoClassDefFoundError: com/envoisolutions/sxc/jaxb/JAXBContextImpl
>        at org.apache.openejb.jee.JaxbJavaee.getContext(JaxbJavaee.java:73)
>        at org.apache.openejb.jee.JaxbJavaee.unmarshal(JaxbJavaee.java:87)
>        at
> org.apache.openejb.config.DeploymentLoader.unmarshal(DeploymentLoader.java:911)
>
> Line 73 is where it references JAXBContextFactory, which in turn has it's
> one and only ref to JAXBContextImpl wrapped in a throwable.
>
> Any ideas on what might be happening?
>
>
> Craziest thing is I can't seem to come up with a more isolated scenario that
> fails.  All my simplified tests work.  Pulling my hair out.
>
> I.e. this works:
>
> ----copy this into your clipboard----
> public class Test {
>
>    public static void main(String[] args) throws Exception {
>        try {
>            OptionalClass.foo();
>        } catch (NoClassDefFoundError e) {
>            System.out.println("Foo is missing, good.");
>        }
>    }
>
>    public static class OptionalClass {
>        public static Object foo() {
>            return null;
>        }
>    }
> }
> ---------------------------------------
>
> And run:
> pbpaste > Test.java && javac Test.java && rm *OptionalClass.class && java
> Test
>
> Works fine.
>
> /me is pulling his hair out
>
> -David
>
>
> On Jan 25, 2008, at 1:48 PM, Guillaume Nodet wrote:
>
>> Yeah, it does :-)
>>
>> On Jan 25, 2008 10:43 PM, David Blevins <da...@visi.com> wrote:
>>
>>>
>>> On Jan 25, 2008, at 11:07 AM, Guillaume Nodet wrote:
>>>
>>>> I've raised a JIRA and attached a small patch to remove a hard
>>>> dependency on
>>>> log4j.
>>>> Please, review
>>>>  https://issues.apache.org/jira/browse/OPENEJB-748
>>>
>>> Wow, does that really work?  Does the NoClassDefFoundError get thrown
>>> from that exact spot such that it can be caught and ignored?  Really
>>> cool if so....  We could use that in a few places.
>>>
>>> -David
>>>
>>>
>>
>>
>> --
>> Cheers,
>> Guillaume Nodet
>> ------------------------
>> Blog: http://gnodet.blogspot.com/
>
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Small patch to remove a hard dependency on log4j

Posted by David Blevins <da...@visi.com>.
I'm trying your trick out on the SXC JAXBContextImpl.  The goal is  
that it can be optional.  For some reason I cannot get it to work in  
any way whatsoever.  Wonder if you have any insight or see something  
I'm missing.

   http://people.apache.org/~dblevins/JAXBContextFactory.java

I'm testing this by marking the "sxc-jaxb" dep as "provided" in  
openejb-jee, thus ensuring it's *not* available in openejb-core at  
test time.  I just keep getting smacked in the face with a  
NoClassDefError:

java.lang.NoClassDefFoundError: com/envoisolutions/sxc/jaxb/ 
JAXBContextImpl
	at org.apache.openejb.jee.JaxbJavaee.getContext(JaxbJavaee.java:73)
	at org.apache.openejb.jee.JaxbJavaee.unmarshal(JaxbJavaee.java:87)
	at  
org 
.apache 
.openejb.config.DeploymentLoader.unmarshal(DeploymentLoader.java:911)

Line 73 is where it references JAXBContextFactory, which in turn has  
it's one and only ref to JAXBContextImpl wrapped in a throwable.

Any ideas on what might be happening?


Craziest thing is I can't seem to come up with a more isolated  
scenario that fails.  All my simplified tests work.  Pulling my hair  
out.

I.e. this works:

----copy this into your clipboard----
public class Test {

     public static void main(String[] args) throws Exception {
         try {
             OptionalClass.foo();
         } catch (NoClassDefFoundError e) {
             System.out.println("Foo is missing, good.");
         }
     }

     public static class OptionalClass {
         public static Object foo() {
             return null;
         }
     }
}
---------------------------------------

And run:
pbpaste > Test.java && javac Test.java && rm *OptionalClass.class &&  
java Test

Works fine.

/me is pulling his hair out

-David


On Jan 25, 2008, at 1:48 PM, Guillaume Nodet wrote:

> Yeah, it does :-)
>
> On Jan 25, 2008 10:43 PM, David Blevins <da...@visi.com>  
> wrote:
>
>>
>> On Jan 25, 2008, at 11:07 AM, Guillaume Nodet wrote:
>>
>>> I've raised a JIRA and attached a small patch to remove a hard
>>> dependency on
>>> log4j.
>>> Please, review
>>>  https://issues.apache.org/jira/browse/OPENEJB-748
>>
>> Wow, does that really work?  Does the NoClassDefFoundError get thrown
>> from that exact spot such that it can be caught and ignored?  Really
>> cool if so....  We could use that in a few places.
>>
>> -David
>>
>>
>
>
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/


Re: Small patch to remove a hard dependency on log4j

Posted by Guillaume Nodet <gn...@gmail.com>.
Yeah, it does :-)

On Jan 25, 2008 10:43 PM, David Blevins <da...@visi.com> wrote:

>
> On Jan 25, 2008, at 11:07 AM, Guillaume Nodet wrote:
>
> > I've raised a JIRA and attached a small patch to remove a hard
> > dependency on
> > log4j.
> > Please, review
> >   https://issues.apache.org/jira/browse/OPENEJB-748
>
> Wow, does that really work?  Does the NoClassDefFoundError get thrown
> from that exact spot such that it can be caught and ignored?  Really
> cool if so....  We could use that in a few places.
>
> -David
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Small patch to remove a hard dependency on log4j

Posted by David Blevins <da...@visi.com>.
On Jan 25, 2008, at 11:07 AM, Guillaume Nodet wrote:

> I've raised a JIRA and attached a small patch to remove a hard  
> dependency on
> log4j.
> Please, review
>   https://issues.apache.org/jira/browse/OPENEJB-748

Wow, does that really work?  Does the NoClassDefFoundError get thrown  
from that exact spot such that it can be caught and ignored?  Really  
cool if so....  We could use that in a few places.

-David