Now I managed the problem with getting the xml file. I used the classloader
from the bundle containing the xml file:
configuration = new DefaultConfiguration().setUserSettingsFile( user
).setClassLoader( DefaultPlexusConfiguration.class.getClassLoader());
But now I am facing the next issues.
Log:
this realm = plexus.core
this strategy = org.codehaus.plexus.classworlds.strategy.ForeignStrategy
Number of imports: 0
-----------------------------------------------------
Caused by:
org.codehaus.plexus.component.repository.exception.ComponentLookupException:
Unable to lookup component 'org.apache.maven.plugin.MavenPluginCollector',
it could not be created.
role: org.apache.maven.plugin.MavenPluginCollector
roleHint: default
classRealm: plexus.core
at
org.codehaus.plexus.DefaultComponentLookupManager.lookup(DefaultComponentLoo
kupManager.java:151)
at
org.codehaus.plexus.DefaultComponentLookupManager.lookup(DefaultComponentLoo
kupManager.java:69)
at
org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.jav
a:431)
at
org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.jav
a:425)
at
org.codehaus.plexus.container.initialization.InitializeComponentDiscovererMa
nagerPhase.initializeCoreComponent(InitializeComponentDiscovererManagerPhase
.java:51)
... 55 more
Caused by:
org.codehaus.plexus.component.factory.ComponentInstantiationException: Could
not instantiate component: role:
'org.apache.maven.plugin.MavenPluginCollector', implementation:
'org.apache.maven.plugin.MavenPluginCollector', role hint: 'default' realm:
plexus.core
at
org.codehaus.plexus.component.factory.java.JavaComponentFactory.makeExceptio
n(JavaComponentFactory.java:116)
at
org.codehaus.plexus.component.factory.java.JavaComponentFactory.newInstance(
JavaComponentFactory.java:82)
at
org.codehaus.plexus.component.manager.AbstractComponentManager.createCompone
ntInstance(AbstractComponentManager.java:203)
at
org.codehaus.plexus.component.manager.AbstractComponentManager.createCompone
ntInstance(AbstractComponentManager.java:125)
at
org.codehaus.plexus.component.manager.ClassicSingletonComponentManager.getCo
mponent(ClassicSingletonComponentManager.java:96)
at
org.codehaus.plexus.DefaultComponentLookupManager.lookup(DefaultComponentLoo
kupManager.java:147)
... 59 more
Caused by: java.lang.ClassNotFoundException:
org.apache.maven.plugin.MavenPluginCollector
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at
org.codehaus.plexus.classworlds.realm.ClassRealm.loadRealmClass(ClassRealm.j
ava:174)
at
org.codehaus.plexus.classworlds.strategy.DefaultStrategy.loadClass(DefaultSt
rategy.java:67)
at
org.codehaus.plexus.classworlds.strategy.ForeignStrategy.loadClass(ForeignSt
rategy.java:39)
at
org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:2
01)
at
org.codehaus.plexus.component.factory.java.JavaComponentFactory.newInstance(
JavaComponentFactory.java:53)
So I think the problem is that the jar is using the classloader I passed in
creating the configuration. Instantiating the component fails because the
classloader cannot find the class and as a consequence I am getting the
ClassNotFoundException.
I tried to add the package org.apache.maven.plugin to the bootdelegation but
it did not work.
Is there a possible workaround for my described class loading issue?
Maybe someone had similar problems using libraries not written as OSGi
bundles?
Thanks,
Alex
Am 28.01.10 17:22 schrieb "Chris Custine" unter <[email protected]>:
> I would say that either the bundle with that xml resource does not export
> the org.codehaus.plexus package where the xml file is, and/or the bundle
> containing your activator does not import that package. If those are both
> true, it should work as far as I can tell.
>
> Chris
>
> --
> Chris Custine
> FUSESource :: http://fusesource.com
> My Blog :: http://blog.organicelement.com
> Apache ServiceMix :: http://servicemix.apache.org
> Apache Felix :: http://felix.apache.org
> Apache Directory Server :: http://directory.apache.org
>
>
> On Thu, Jan 28, 2010 at 5:45 AM, Alexander Blotny <
> [email protected]> wrote:
>
>> Hi,
>>
>> I am trying to use maven embedder inside the Felix OSGi framework.
>> At first I created the MANIFEST files for all the dependencies of maven
>> embedder and used jardir for starting the bundles.
>>
>> Following jars are started:
>>
>> aspectjrt-1.5.3.jar
>> commons-cli-1.0.jar
>> doxia-sink-api-1.0-alpha-9.jar
>> jsch-0.1.27.jar
>> jtidy-4aug2000r7-dev.jar
>> maven-artifact-3.0-SNAPSHOT.jar
>> maven-core-2.1-SNAPSHOT.jar
>> maven-embedder-2.1-SNAPSHOT.jar
>> maven-lifecycle-2.1-SNAPSHOT.jar
>> maven-model-2.1-SNAPSHOT.jar
>> maven-plugin-api-2.1-SNAPSHOT.jar
>> maven-profile-2.1-SNAPSHOT.jar
>> maven-project-2.1-SNAPSHOT.jar
>> maven-reporting-api-2.1-SNAPSHOT.jar
>> maven-toolchain-2.1-SNAPSHOT.jar
>> maven-workspace-2.1-SNAPSHOT.jar
>> plexus-classworlds-1.2-alpha-12.jar
>> plexus-container-default-1.0-alpha-44.jar
>> plexus-interactivity-api-1.0-alpha-6.jar
>> plexus-interpolation-1.0-SNAPSHOT.jar
>> plexus-utils-1.5.1.jar
>> wagon-file-1.0-beta-2.jar
>> wagon-http-lightweight-1.0-beta-2.jar
>> wagon-http-shared-1.0-beta-2.jar
>> wagon-provider-api-1.0-beta-2.jar
>> wagon-ssh-1.0-beta-2.jar
>> wagon-ssh-common-1.0-beta-2.jar
>> wagon-ssh-external-1.0-beta-2.jar
>>
>> Using maven embedder from within eclipse was no problem but starting it in
>> the OSGi framework throws exceptions.
>> The code for using maven embedder I got from the apache maven homepage
>> (excerpt) and started it in the Activator of a bundle:
>>
>> File projectDirectory = new File(folder);
>> File user = new File(projectDirectory, "settings.xml");
>> Configuration configuration = new
>> DefaultConfiguration().setUserSettingsFile( user ).setClassLoader(
>> context.getBundle().getClass().getClassLoader() );
>> ConfigurationValidationResult validationResult =
>> MavenEmbedder.validateConfiguration(configuration);
>> if ( validationResult.isValid() )
>> {
>> MavenEmbedder embedder = null;
>> try {
>> embedder = new MavenEmbedder( configuration );
>> } catch (MavenEmbedderException e) {
>> e.printStackTrace();
>> }
>> }
>>
>> As you can see, as Classloader I am using the one from the bundle.
>> The problem is now that inside the jar plexus-container is a resource as
>> xml
>> which is accessed via getResourceStream of the Classloader. But the
>> resource
>> cannot be found:
>>
>> java.lang.IllegalStateException: The internal default plexus-bootstrap.xml
>> is missing. This is highly irregular, your plexus JAR is most likely
>> corrupt. Realms:
>> plexus.core parent=sun.misc.launcher$appclassloa...@6a765291 (null)
>> at
>>
>> org.codehaus.plexus.DefaultPlexusContainer.initializeConfiguration(DefaultPl
>> exusContainer.java:1017) [na:na]
>> at
>>
>> org.codehaus.plexus.DefaultPlexusContainer.initialize(DefaultPlexusContainer
>> .java:812) [na:na]
>> at
>>
>> org.codehaus.plexus.DefaultPlexusContainer.construct(DefaultPlexusContainer.
>> java:406) [na:na]
>> at
>>
>> org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.jav
>> a:199) [na:na]
>> at org.apache.maven.embedder.MavenEmbedder.start(MavenEmbedder.java:652)
>> [na:na]
>> at
>> org.apache.maven.embedder.MavenEmbedder.<init>(MavenEmbedder.java:198)
>> [na:na]
>>
>> The source code of accessing the xml file in plexus-container.jar looks
>> like
>> this:
>>
>> InputStream is = containerRealm.getResourceAsStream(
>> "org/codehaus/plexus/plexus-bootstrap.xml" ); if ( is == null )
>> { ClassRealm cr = containerRealm; String realmStack =
>> ""; while ( cr != null ) { realmStack
>> += "\n " + cr.getId() + " parent=" + cr.getParent() + " ("
>> + cr.getResource( "org/codehaus/plexus/plexus-bootstrap.xml" ) + ")";
>> cr = cr.getParentRealm(); }
>> containerRealm.display();
>> throw new IllegalStateException( "The internal default plexus-bootstrap.xml
>> is missing. " + "This is highly irregular, your plexus JAR
>> is
>> most likely corrupt. Realms:" + realmStack ); }
>>
>> Is there a possibility to assure access to that resource without changing
>> the source code?
>> Has anyone an idea?
>>
>> Thanks,
>> Alex
>>
>>
>>