# OSGI classloader issue

**URL:** <https://forum.liquibase.org/t/osgi-classloader-issue/1298>\
**Category:** General Discussion\
**Created:** [June 11, 2011, 6:47pm UTC](https://forum.liquibase.org/t/osgi-classloader-issue/1298 "2011-06-11T18:47:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guest](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@Guest](https://forum.liquibase.org/u/Guest)\
**Post date:** [June 11, 2011, 6:47pm UTC](https://forum.liquibase.org/t/osgi-classloader-issue/1298/1 "2011-06-11T18:47:00Z")

</div>

Attempting to run liquibase within an Eclipse RCP yeilds the following error in liquibase 2.0.1:

Could not find implementation of liquibase.logging.Logger

I'm assuming this is related to the disperate classloading - is there a strategy or workaround which allows the liquibase serviceLocator to locate classes within an osgi bundle?

---

<div class="post-metadata">

**Author:** ![eike\_kettner](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@eike\_kettner](https://forum.liquibase.org/u/eike_kettner)\
**Post date:** [June 11, 2011, 6:47pm UTC](https://forum.liquibase.org/t/osgi-classloader-issue/1298/2 "2011-06-11T18:47:00Z")

</div>

Hi

I think the&nbsp;DefaultPackageScanResolver&nbsp;doesn’t work with OSGi. As far as I can see, the DefaultPackageScanResolver lists classes from either the filesystem or a jar file in order to find implementations. But it cannot do so for OSGi bundles ([http://grepcode.com/file/repo1.maven.org/maven2/org.liquibase/liquibase-core/2.0.1/liquibase/servicelocator/DefaultPackageScanClassResolver.java#169](http://grepcode.com/file/repo1.maven.org/maven2/org.liquibase/liquibase-core/2.0.1/liquibase/servicelocator/DefaultPackageScanClassResolver.java#169)).

Maybe one can create a compatible PackageScanClassResolver that doesnt scan packages but looks up services from the OSGi registry (or better to create a compatible ServiceLocator, so its newInstance() method can return the service directly from the registry). This way it’s possible to find implementations of interfaces (not subclasses of “normal” classes, though) – and one would have to register every implementation to the registry – which are quite a few… &nbsp;A BundleActivator can then just instantiate either the new ServiceLocator or set the osgi-enabled class resolver.&nbsp;

I just gave it a quick try &nbsp;with a very simple changelog that only creates a table and inserts a row. But I don’t know liquibase code well enough, maybe this won’t work in real world. &nbsp;I have no idea for a “simple” workaround.

Regards,

Eike

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [June 11, 2011, 6:47pm UTC](https://forum.liquibase.org/t/osgi-classloader-issue/1298/3 "2011-06-11T18:47:00Z")

</div>

I haven’t dealt with OSGi much. Does anyone with more experience have an idea of the problem?  
  
Nathan

---

<div class="post-metadata">

**Author:** ![nvoxland](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@nvoxland](https://forum.liquibase.org/u/nvoxland)\
**Post date:** [June 11, 2011, 6:47pm UTC](https://forum.liquibase.org/t/osgi-classloader-issue/1298/4 "2011-06-11T18:47:00Z")

</div>

Yes, you will have to create a new ClassResolver. Using the extension system ([liquibase.org/extensions](http://liquibase.org/extensions)) you should be able to have the new resolver picked up without needing to rebuild or modify liquibase, although I haven’t tested that particular extension point much.

Nathan

---

<div class="post-metadata">

**Author:** ![Guest](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@Guest](https://forum.liquibase.org/u/Guest)\
**Post date:** [June 11, 2011, 6:47pm UTC](https://forum.liquibase.org/t/osgi-classloader-issue/1298/5 "2011-06-11T18:47:00Z")

</div>

I just ran in to the same problem with 2.0.1 and Equinox. &nbsp;Could you expand more on how to create a new ClassResolver? &nbsp;Looking at the source, it appears the ServiceLocator directly instantiates the&nbsp;DefaultPackageScanResolver.

Thanks,

Michael

---

<div class="post-metadata">

**Author:** ![Guest](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@Guest](https://forum.liquibase.org/u/Guest)\
**Post date:** [June 11, 2011, 6:47pm UTC](https://forum.liquibase.org/t/osgi-classloader-issue/1298/6 "2011-06-11T18:47:00Z")

</div>

You can set your own instance of a ServiceLocator via ServiceLocator.setInstance(new CustomResolverServiceLocator(…))  
  
Stefan
