You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Ac...@emc.com on 2010/04/22 16:01:30 UTC

non-OSGi jar exported via "org.osgi.framework.system.packages.extra" accessing bundle packages

Hi,

 

I have deployed Perf4j as a non-OSGi jar exported via
"org.osgi.framework.system.packages.extra".  Perf4j has a dependency on
org.slf4j.Logger, which I have deployed as a bundle (as there are other
bundles dependent on this SLF4j version).  During runtime, I get
ClassNotFoundException.

 

How is the wiring between non-OSGi jar & bundles handled?  

How do we deal with a situation where a package A is needed by both
non-OSGI & OSGi bundle deployed on Apache Felix?

 

Thanks,

Prakash


Re: non-OSGi jar exported via "org.osgi.framework.system.packages.extra" accessing bundle packages

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 4/22/10 10:21, Justin Edelson wrote:
> On 4/22/10 10:06 AM, Richard S. Hall wrote:
>    
>> On 4/22/10 10:01, Achuthan_Prakash@emc.com wrote:
>>      
>>> Hi,
>>>
>>>
>>>
>>> I have deployed Perf4j as a non-OSGi jar exported via
>>> "org.osgi.framework.system.packages.extra".  Perf4j has a dependency on
>>> org.slf4j.Logger, which I have deployed as a bundle (as there are other
>>> bundles dependent on this SLF4j version).  During runtime, I get
>>> ClassNotFoundException.
>>>
>>>
>>>
>>> How is the wiring between non-OSGi jar&   bundles handled?
>>>
>>> How do we deal with a situation where a package A is needed by both
>>> non-OSGI&   OSGi bundle deployed on Apache Felix?
>>>
>>>        
>> Packages on the class path cannot "import" from bundles. You will need
>> to add any needed packages to the class path too and export them using
>> system.packages.extra as well if you want them to be shared among the
>> class path packages and the deployed bundles.
>>      
> Although in this case, if SLF4J isn't part of the exported API, then it
> need not be exported, right? In other words, if you have:
>
> package foo.bar;
>
> import org.slf4j.*;
>
> public class MyClass {
>    private Logger logger = LoggerFactory.getLogger(MyClass.class);
>
>    public void doSomething() {
>      // ...
>    }
>
> }
>
> Then you can export foo.bar without exporting org.slf4j.
>    

Yes, that's what I meant by "if you want them to be shared among ... the 
deployed bundles." That probably wasn't entirely clear. So, you are 
correct. If the package is just used by the class path packages, but not 
exposed by them, then just add the needed packages to the class path and 
do not export them from the system bundle.

-> richard

> Justin
>
>    
>> ->  richard
>>
>>      
>>>
>>> Thanks,
>>>
>>> Prakash
>>>
>>>
>>>
>>>        
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>      
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>    

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: non-OSGi jar exported via "org.osgi.framework.system.packages.extra" accessing bundle packages

Posted by Justin Edelson <ju...@gmail.com>.
On 4/22/10 10:06 AM, Richard S. Hall wrote:
> On 4/22/10 10:01, Achuthan_Prakash@emc.com wrote:
>> Hi,
>>
>>
>>
>> I have deployed Perf4j as a non-OSGi jar exported via
>> "org.osgi.framework.system.packages.extra".  Perf4j has a dependency on
>> org.slf4j.Logger, which I have deployed as a bundle (as there are other
>> bundles dependent on this SLF4j version).  During runtime, I get
>> ClassNotFoundException.
>>
>>
>>
>> How is the wiring between non-OSGi jar&  bundles handled?
>>
>> How do we deal with a situation where a package A is needed by both
>> non-OSGI&  OSGi bundle deployed on Apache Felix?
>>    
> 
> Packages on the class path cannot "import" from bundles. You will need
> to add any needed packages to the class path too and export them using
> system.packages.extra as well if you want them to be shared among the
> class path packages and the deployed bundles.
Although in this case, if SLF4J isn't part of the exported API, then it
need not be exported, right? In other words, if you have:

package foo.bar;

import org.slf4j.*;

public class MyClass {
  private Logger logger = LoggerFactory.getLogger(MyClass.class);

  public void doSomething() {
    // ...
  }

}

Then you can export foo.bar without exporting org.slf4j.

Justin

> 
> -> richard
> 
>>
>>
>> Thanks,
>>
>> Prakash
>>
>>
>>    
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: non-OSGi jar exported via "org.osgi.framework.system.packages.extra" accessing bundle packages

Posted by "Richard S. Hall" <he...@ungoverned.org>.
It looks like your bundle has access to more than one copy of the 
logging package. You likely need to not provide the package in your 
deployed bundles...if this is not an option, you can cheat and list this 
package on the boot delegation property so all requests for it come from 
the class path...if you do this you'll likely also have to set the 
parent class loader property to be the same as the application class loader.

-> richard

On 4/22/10 10:13, Achuthan_Prakash@emc.com wrote:
> Thanks Richard.  But I am getting the following error when I do that:
>
> Exception in thread "SpringOsgiExtenderThread-3"
> org.springframework.beans.factory.BeanCreationException: Error creating
> bean with name 'eventmanagerOSGi' defined in URL
> [bundle://47.0:0/META-INF/spring/springDMEventManagerAppContext.xml]:
> Invocation of init method failed; nested exception is
> java.lang.LinkageError: loader constraint violation: loader (instance of
> sun/misc/Launcher$AppClassLoader) previously initiated loading for a
> different type with name "org/slf4j/Logger"
>          at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
>          at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
>          at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory$1.run(AbstractAutowireCapableBeanFactory.java:409)
>          at java.security.AccessController.doPrivileged(Native Method)
>          at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.createBean(AbstractAutowireCapableBeanFactory.java:380)
>          at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObjec
> t(AbstractBeanFactory.java:264)
>          at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.g
> etSingleton(DefaultSingletonBeanRegistry.java:222)
>          at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(
> AbstractBeanFactory.java:261)
>          at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ab
> stractBeanFactory.java:185)
>          at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ab
> stractBeanFactory.java:164)
>          at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.pre
> InstantiateSingletons(DefaultListableBeanFactory.java:429)
>          at
> org.springframework.context.support.AbstractApplicationContext.finishBea
> nFactoryInitialization(AbstractApplicationContext.java:728)
>          at
> org.springframework.osgi.context.support.AbstractDelegatedExecutionAppli
> cationContext.access$1600(AbstractDelegatedExecutionApplicationContext.j
> ava:69)
>          at
> org.springframework.osgi.context.support.AbstractDelegatedExecutionAppli
> cationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:35
> 5)
>          at
> org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustom
> TCCL(PrivilegedUtils.java:85)
>          at
> org.springframework.osgi.context.support.AbstractDelegatedExecutionAppli
> cationContext.completeRefresh(AbstractDelegatedExecutionApplicationConte
> xt.java:320)
>          at
> org.springframework.osgi.extender.internal.dependencies.startup.Dependen
> cyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWai
> terApplicationContextExecutor.java:136)
>          at java.lang.Thread.run(Unknown Source)
> Caused by: java.lang.LinkageError: loader constraint violation: loader
> (instance of sun/misc/Launcher$AppClassLoader) previously initiated
> loading for a different type with name "org/slf4j/Logger"
>          at java.lang.ClassLoader.defineClass1(Native Method)
>          at java.lang.ClassLoader.defineClass(Unknown Source)
>          at java.security.SecureClassLoader.defineClass(Unknown Source)
>          at java.net.URLClassLoader.defineClass(Unknown Source)
>          at java.net.URLClassLoader.access$000(Unknown Source)
>          at java.net.URLClassLoader$1.run(Unknown Source)
>          at java.security.AccessController.doPrivileged(Native Method)
>          at java.net.URLClassLoader.findClass(Unknown Source)
>          at java.lang.ClassLoader.loadClass(Unknown Source)
>          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
>          at java.lang.ClassLoader.loadClass(Unknown Source)
>          at java.lang.ClassLoader.loadClassInternal(Unknown Source)
>          at org.perf4j.slf4j.Slf4JStopWatch.log(Slf4JStopWatch.java:407)
>          at org.perf4j.slf4j.Slf4JStopWatch.log(Slf4JStopWatch.java:359)
>          at
> org.perf4j.LoggingStopWatch.doLogInternal(LoggingStopWatch.java:238)
>          at org.perf4j.LoggingStopWatch.stop(LoggingStopWatch.java:130)
>          at org.perf4j.StopWatch.stop(StopWatch.java:209)
>          at
> com.emc.srm.event.manager.service.EventManagerService.start(EventManager
> Service.java:146)
>          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
> Source)
>          at java.lang.reflect.Method.invoke(Unknown Source)
>          at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414
> )
>          at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375)
>          at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
>          ... 17 more
>
>
> - Prakash
>
> -----Original Message-----
> From: Richard S. Hall [mailto:heavy@ungoverned.org]
> Sent: Thursday, April 22, 2010 7:37 PM
> To: users@felix.apache.org
> Subject: Re: non-OSGi jar exported via
> "org.osgi.framework.system.packages.extra" accessing bundle packages
>
> On 4/22/10 10:01, Achuthan_Prakash@emc.com wrote:
>    
>> Hi,
>>
>>
>>
>> I have deployed Perf4j as a non-OSGi jar exported via
>> "org.osgi.framework.system.packages.extra".  Perf4j has a dependency
>>      
> on
>    
>> org.slf4j.Logger, which I have deployed as a bundle (as there are
>>      
> other
>    
>> bundles dependent on this SLF4j version).  During runtime, I get
>> ClassNotFoundException.
>>
>>
>>
>> How is the wiring between non-OSGi jar&   bundles handled?
>>
>> How do we deal with a situation where a package A is needed by both
>> non-OSGI&   OSGi bundle deployed on Apache Felix?
>>
>>      
> Packages on the class path cannot "import" from bundles. You will need
> to add any needed packages to the class path too and export them using
> system.packages.extra as well if you want them to be shared among the
> class path packages and the deployed bundles.
>
> ->  richard
>
>    
>>
>> Thanks,
>>
>> Prakash
>>
>>
>>
>>      
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>    

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


RE: non-OSGi jar exported via "org.osgi.framework.system.packages.extra" accessing bundle packages

Posted by Ac...@emc.com.
Thanks Richard.  But I am getting the following error when I do that:

Exception in thread "SpringOsgiExtenderThread-3"
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'eventmanagerOSGi' defined in URL
[bundle://47.0:0/META-INF/spring/springDMEventManagerAppContext.xml]:
Invocation of init method failed; nested exception is
java.lang.LinkageError: loader constraint violation: loader (instance of
sun/misc/Launcher$AppClassLoader) previously initiated loading for a
different type with name "org/slf4j/Logger"
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory$1.run(AbstractAutowireCapableBeanFactory.java:409)
        at java.security.AccessController.doPrivileged(Native Method)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.createBean(AbstractAutowireCapableBeanFactory.java:380)
        at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObjec
t(AbstractBeanFactory.java:264)
        at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.g
etSingleton(DefaultSingletonBeanRegistry.java:222)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(
AbstractBeanFactory.java:261)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ab
stractBeanFactory.java:185)
        at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ab
stractBeanFactory.java:164)
        at
org.springframework.beans.factory.support.DefaultListableBeanFactory.pre
InstantiateSingletons(DefaultListableBeanFactory.java:429)
        at
org.springframework.context.support.AbstractApplicationContext.finishBea
nFactoryInitialization(AbstractApplicationContext.java:728)
        at
org.springframework.osgi.context.support.AbstractDelegatedExecutionAppli
cationContext.access$1600(AbstractDelegatedExecutionApplicationContext.j
ava:69)
        at
org.springframework.osgi.context.support.AbstractDelegatedExecutionAppli
cationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:35
5)
        at
org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustom
TCCL(PrivilegedUtils.java:85)
        at
org.springframework.osgi.context.support.AbstractDelegatedExecutionAppli
cationContext.completeRefresh(AbstractDelegatedExecutionApplicationConte
xt.java:320)
        at
org.springframework.osgi.extender.internal.dependencies.startup.Dependen
cyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWai
terApplicationContextExecutor.java:136)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.LinkageError: loader constraint violation: loader
(instance of sun/misc/Launcher$AppClassLoader) previously initiated
loading for a different type with name "org/slf4j/Logger"
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at org.perf4j.slf4j.Slf4JStopWatch.log(Slf4JStopWatch.java:407)
        at org.perf4j.slf4j.Slf4JStopWatch.log(Slf4JStopWatch.java:359)
        at
org.perf4j.LoggingStopWatch.doLogInternal(LoggingStopWatch.java:238)
        at org.perf4j.LoggingStopWatch.stop(LoggingStopWatch.java:130)
        at org.perf4j.StopWatch.stop(StopWatch.java:209)
        at
com.emc.srm.event.manager.service.EventManagerService.start(EventManager
Service.java:146)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414
)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375)
        at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
        ... 17 more


- Prakash

-----Original Message-----
From: Richard S. Hall [mailto:heavy@ungoverned.org] 
Sent: Thursday, April 22, 2010 7:37 PM
To: users@felix.apache.org
Subject: Re: non-OSGi jar exported via
"org.osgi.framework.system.packages.extra" accessing bundle packages

On 4/22/10 10:01, Achuthan_Prakash@emc.com wrote:
> Hi,
>
>
>
> I have deployed Perf4j as a non-OSGi jar exported via
> "org.osgi.framework.system.packages.extra".  Perf4j has a dependency
on
> org.slf4j.Logger, which I have deployed as a bundle (as there are
other
> bundles dependent on this SLF4j version).  During runtime, I get
> ClassNotFoundException.
>
>
>
> How is the wiring between non-OSGi jar&  bundles handled?
>
> How do we deal with a situation where a package A is needed by both
> non-OSGI&  OSGi bundle deployed on Apache Felix?
>    

Packages on the class path cannot "import" from bundles. You will need 
to add any needed packages to the class path too and export them using 
system.packages.extra as well if you want them to be shared among the 
class path packages and the deployed bundles.

-> richard

>
>
> Thanks,
>
> Prakash
>
>
>    

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: non-OSGi jar exported via "org.osgi.framework.system.packages.extra" accessing bundle packages

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 4/22/10 10:01, Achuthan_Prakash@emc.com wrote:
> Hi,
>
>
>
> I have deployed Perf4j as a non-OSGi jar exported via
> "org.osgi.framework.system.packages.extra".  Perf4j has a dependency on
> org.slf4j.Logger, which I have deployed as a bundle (as there are other
> bundles dependent on this SLF4j version).  During runtime, I get
> ClassNotFoundException.
>
>
>
> How is the wiring between non-OSGi jar&  bundles handled?
>
> How do we deal with a situation where a package A is needed by both
> non-OSGI&  OSGi bundle deployed on Apache Felix?
>    

Packages on the class path cannot "import" from bundles. You will need 
to add any needed packages to the class path too and export them using 
system.packages.extra as well if you want them to be shared among the 
class path packages and the deployed bundles.

-> richard

>
>
> Thanks,
>
> Prakash
>
>
>    

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org