You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steinar Bang <sb...@dod.no> on 2018/09/09 12:30:42 UTC

Problems accessing SystemMBean from a DS component

Platform: debian 9.5 "stretch", amd64
          openjdk-8-jdk 8u181-b13-1~deb9u1
          karaf 4.1.5

(Note: This is a project very much in the start phase so I haven't pushed
anything to github yet)

I'm trying to inject a SystemMBean into a DS component.  When I try
this, loading the feature holding the component, fails with an error
message:
 karaf@root()> feature:repo-add mvn:no.priv.bang.neo4j.karaf/neo4j-karaf/LATEST/xml/features
 Adding feature url mvn:no.priv.bang.neo4j.karaf/neo4j-karaf/LATEST/xml/features
 karaf@root()> feature:install neo4j-server
 Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=neo4j-server; type=karaf.feature; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; filter:="(&(osgi.identity=neo4j-server)(type=karaf.feature)(version>=1.0.0.SNAPSHOT)(version<=1.0.0.SNAPSHOT))" [caused by: Unable to resolve neo4j-server/1.0.0.SNAPSHOT: missing requirement [neo4j-server/1.0.0.SNAPSHOT] osgi.identity; osgi.identity=no.priv.bang.neo4j.karaf; type=osgi.bundle; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve no.priv.bang.neo4j.karaf/1.0.0.SNAPSHOT: missing requirement [no.priv.bang.neo4j.karaf/1.0.0.SNAPSHOT] osgi.service; filter:="(objectClass=org.apache.karaf.system.management.SystemMBean)"; effective:=active]]
 karaf@root()>

The karaf.log has this:
 2018-09-09T14:22:47,172 | ERROR | Karaf local console user karaf | ShellUtil                        | 43 - org.apache.karaf.shell.core - 4.1.5 | Exception caught while executing command
org.osgi.service.resolver.ResolutionException: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=neo4j-server; type=karaf.feature; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; filter:="(&(osgi.identity=neo4j-server)(type=karaf.feature)(version>=1.0.0.SNAPSHOT)(version<=1.0.0.SNAPSHOT))" [caused by: Unable to resolve neo4j-server/1.0.0.SNAPSHOT: missing requirement [neo4j-server/1.0.0.SNAPSHOT] osgi.identity; osgi.identity=no.priv.bang.neo4j.karaf; type=osgi.bundle; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve no.priv.bang.neo4j.karaf/1.0.0.SNAPSHOT: missing requirement [no.priv.bang.neo4j.karaf/1.0.0.SNAPSHOT] osgi.service; filter:="(objectClass=org.apache.karaf.system.management.SystemMBean)"; effective:=active]]
 	at org.apache.felix.resolver.ResolutionError.toException(ResolutionError.java:42) ~[?:?]
 	at org.apache.felix.resolver.ResolverImpl.doResolve(ResolverImpl.java:391) ~[?:?]
 	at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:377) ~[?:?]
 	at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:349) ~[?:?]
 	at org.apache.karaf.features.internal.region.SubsystemResolver.resolve(SubsystemResolver.java:218) ~[?:?]
 	at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:291) ~[?:?]
 	at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1248) ~[?:?]
 	at org.apache.karaf.features.internal.service.FeaturesServiceImpl.lambda$doProvisionInThread$1(FeaturesServiceImpl.java:1147) ~[?:?]
 	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
 	at java.lang.Thread.run(Thread.java:748) [?:?]


Does anyone know what I might be missing?

What I have done, is:
 1. Add org.apache.karaf.system.core as a provided dependency
        <dependency>
            <groupId>org.apache.karaf.system</groupId>
            <artifactId>org.apache.karaf.system.core</artifactId>
            <version>${karaf.version}</version>
            <scope>provided</scope>
        </dependency>
 2. Add a @Reference for the SystemMBean to the DS component

As a shot in the dark, I have also tried adding a
<feature>system</feature> dependency to the template feature.xml of my
feature (it shouldn't be necessary, but it was woth a try).

As far as I can tell, the "system" bundle is alive and loaded, and
exposes the service I'm trying to inject:
 karaf@root()> bundle:list -t 1 org.apache.karaf.system.core
 START LEVEL 100 , List Threshold: 1
 ID │ State  │ Lvl │ Version │ Name
 ───┼────────┼─────┼─────────┼────────────────────────────────
 46 │ Active │  30 │ 4.1.5   │ Apache Karaf :: System :: Core
 karaf@root()> bundle:capabilities org.apache.karaf.system.core
 org.apache.karaf.system.core [46] provides:
 -------------------------------------------
 osgi.wiring.bundle; org.apache.karaf.system.core 4.1.5 [UNUSED]
 osgi.wiring.host; org.apache.karaf.system.core 4.1.5 [UNUSED]
 osgi.identity; org.apache.karaf.system.core 4.1.5 [UNUSED]
 osgi.wiring.package; org.apache.karaf.system 4.1.5 [UNUSED]
 osgi.wiring.package; org.apache.karaf.system.management 4.1.5 [UNUSED]
 service; [org.apache.karaf.system.SystemService] with properties:
    service.bundleid = 46
    service.id = 72
    service.scope = singleton
    Used by:
       org.apache.karaf.system.core [46]
 service; [org.apache.karaf.system.management.SystemMBean, javax.management.DynamicMBean, javax.management.MBeanRegistration] with properties:
    jmx.objectname = org.apache.karaf:type=system,name=root
    service.bundleid = 46
    service.id = 73
    service.scope = singleton
    Used by:
       org.apache.aries.jmx.whiteboard [18]
 karaf@root()>

The org.apache.karaf.system.core bundle exports the
org.apache.karaf.system.management package:
 Export-Package: org.apache.karaf.system;version="4.1.5",org.apache.kar
  af.system.management;uses:="javax.management";version="4.1.5"

My bundle imports the org.apache.karaf.system.management package:
 Import-Package: org.apache.karaf.system.management;version="[4.1,5)",o
  rg.neo4j.graphdb,org.neo4j.graphdb.event,org.neo4j.graphdb.factory,or
  ...

Is there anything else I should check?

Thanks!


Re: Resolving a type from a wrapped jar file

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

Instead of importing packages, you can embed the packages in your bundle.

You have three ways to achieve this using the maven-bundle-plugin:

1. Using Bundle-Classpath instruction
2. Using Embed-Dependency instruction
3. Using Private-Package instruction

Regards
JB

On 09/09/2018 21:35, Steinar Bang wrote:
>>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:
> 
>> why you don't just put this as private package. You will avoid class
>> loading issue this way.
> 
>> In OSGi, not all is necessary an import. It could be a private package
>> and/or embed dependency. It means the packages are embedded in the
>> bundle. The bundle is "fat" but you avoid classloading issue this way,
>> especially when the dependency is not designed for OSGi.
> 
> Um... not sure what you mean...?  Do you mean rebundling Neo4J before
> pulling it into karaf?  Either individually (*lots* of work, probably),
> or as a fat jar (less work if the maven dependencies of the top jar can
> be made to do the trick).
> 
>> Unfortunately, I wanted to create neo4j bundle at ServiceMix, but it's
>> not possible due to neo4j license.
> 
> Yeah, the licensing was why I didn't rebundle with maven in the first
> place.  I hoped the wrap protocol could do the trick...
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Resolving a type from a wrapped jar file

Posted by David Jencks <da...@gmail.com>.
Hi David,

Bundle-ClassPath is an osgi header that specifies the internal class path structure of a bundle. -conditionalpackage is a bnd instruction that pulls in specific packages that are actually used from dependencies.

I was suggesting including all of neo4j in the bundle using the -includeresource bnd instruction and setting the Bundle-ClassPath header by hand to include the normal bundle contents under . and also all the neo4j jars copied in using the -includeresource instruction.  If you wanted to use this idea in your bundle without distributing neo4j at all, you could include the Bundle-ClassPath header and ask users to run a zip command to add the neo4j jars themselves.

I don’t remember what you may have to do to get bnd to not generate Import-Package headers for the packages in the included jars.

My idea with this over -conditionalpackage is that you are using the neo4j jars completely unmodified, but contained in an appropriate osgi environment (completely hidden inside the bundle).  -conditionalpackage is a considerably more sophisticated approach, if you are comfortable with the licensing implications.


thanks
david jencks

> On Sep 9, 2018, at 4:35 PM, David Leangen <ap...@leangen.net> wrote:
> 
> 
> Thanks for this info.
> 
> Could you please explain more what you mean by:
> 
>> uses bundle-classpath
> 
> 
> Is this something different from Conditional-Package?
> 
> 
> Cheers,
> =David
> 
> 
>> On Sep 10, 2018, at 6:31, David Jencks <da...@gmail.com> wrote:
>> 
>> IANAL and I really can’t understand the GPLv3.
>> 
>> rebundling or wrapping neo4j jars definitely modifies them.  I’m not sure if having karaf or maven do this on the user’s system compared with distributing such already modified jars makes a difference to the license implications.
>> 
>> If you make a jar that embeds the neo4j jars (as jars) and uses bundle-classpath you are not modifying the neo4j jars at all.  Doing this, you can hide neo4j from the outside of your bundle and provide an API that does exactly what your program needs.  Peter Kriens highly recommends doing this with external  dependencies that are not designed from the start for OSGI.
>> 
>> To repeat, I don’t understand GPLv3.  If it prevents you from distributing a bundle with your code, also embedding the neo4j jars, I don’t see how it could prevent you from distributing your code plus a script that constructs such a bundle; such a script would just be something that puts neo4j jars in a particular place in a production system.
>> 
>> David Jencks
>> 
>>> On Sep 9, 2018, at 12:35 PM, Steinar Bang <sb...@dod.no> wrote:
>>> 
>>>>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:
>>> 
>>>> why you don't just put this as private package. You will avoid class
>>>> loading issue this way.
>>> 
>>>> In OSGi, not all is necessary an import. It could be a private package
>>>> and/or embed dependency. It means the packages are embedded in the
>>>> bundle. The bundle is "fat" but you avoid classloading issue this way,
>>>> especially when the dependency is not designed for OSGi.
>>> 
>>> Um... not sure what you mean...?  Do you mean rebundling Neo4J before
>>> pulling it into karaf?  Either individually (*lots* of work, probably),
>>> or as a fat jar (less work if the maven dependencies of the top jar can
>>> be made to do the trick).
>>> 
>>>> Unfortunately, I wanted to create neo4j bundle at ServiceMix, but it's
>>>> not possible due to neo4j license.
>>> 
>>> Yeah, the licensing was why I didn't rebundle with maven in the first
>>> place.  I hoped the wrap protocol could do the trick...
>>> 
>> 
> 


Re: Resolving a type from a wrapped jar file

Posted by David Leangen <ap...@leangen.net>.
Thanks for this info.

Could you please explain more what you mean by:

> uses bundle-classpath


Is this something different from Conditional-Package?


Cheers,
=David


> On Sep 10, 2018, at 6:31, David Jencks <da...@gmail.com> wrote:
> 
> IANAL and I really can’t understand the GPLv3.
> 
> rebundling or wrapping neo4j jars definitely modifies them.  I’m not sure if having karaf or maven do this on the user’s system compared with distributing such already modified jars makes a difference to the license implications.
> 
> If you make a jar that embeds the neo4j jars (as jars) and uses bundle-classpath you are not modifying the neo4j jars at all.  Doing this, you can hide neo4j from the outside of your bundle and provide an API that does exactly what your program needs.  Peter Kriens highly recommends doing this with external  dependencies that are not designed from the start for OSGI.
> 
> To repeat, I don’t understand GPLv3.  If it prevents you from distributing a bundle with your code, also embedding the neo4j jars, I don’t see how it could prevent you from distributing your code plus a script that constructs such a bundle; such a script would just be something that puts neo4j jars in a particular place in a production system.
> 
> David Jencks
> 
>> On Sep 9, 2018, at 12:35 PM, Steinar Bang <sb...@dod.no> wrote:
>> 
>>>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:
>> 
>>> why you don't just put this as private package. You will avoid class
>>> loading issue this way.
>> 
>>> In OSGi, not all is necessary an import. It could be a private package
>>> and/or embed dependency. It means the packages are embedded in the
>>> bundle. The bundle is "fat" but you avoid classloading issue this way,
>>> especially when the dependency is not designed for OSGi.
>> 
>> Um... not sure what you mean...?  Do you mean rebundling Neo4J before
>> pulling it into karaf?  Either individually (*lots* of work, probably),
>> or as a fat jar (less work if the maven dependencies of the top jar can
>> be made to do the trick).
>> 
>>> Unfortunately, I wanted to create neo4j bundle at ServiceMix, but it's
>>> not possible due to neo4j license.
>> 
>> Yeah, the licensing was why I didn't rebundle with maven in the first
>> place.  I hoped the wrap protocol could do the trick...
>> 
> 


Re: Resolving a type from a wrapped jar file

Posted by David Jencks <da...@gmail.com>.
IANAL and I really can’t understand the GPLv3.

rebundling or wrapping neo4j jars definitely modifies them.  I’m not sure if having karaf or maven do this on the user’s system compared with distributing such already modified jars makes a difference to the license implications.

If you make a jar that embeds the neo4j jars (as jars) and uses bundle-classpath you are not modifying the neo4j jars at all.  Doing this, you can hide neo4j from the outside of your bundle and provide an API that does exactly what your program needs.  Peter Kriens highly recommends doing this with external  dependencies that are not designed from the start for OSGI.

To repeat, I don’t understand GPLv3.  If it prevents you from distributing a bundle with your code, also embedding the neo4j jars, I don’t see how it could prevent you from distributing your code plus a script that constructs such a bundle; such a script would just be something that puts neo4j jars in a particular place in a production system.  

David Jencks

> On Sep 9, 2018, at 12:35 PM, Steinar Bang <sb...@dod.no> wrote:
> 
>>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:
> 
>> why you don't just put this as private package. You will avoid class
>> loading issue this way.
> 
>> In OSGi, not all is necessary an import. It could be a private package
>> and/or embed dependency. It means the packages are embedded in the
>> bundle. The bundle is "fat" but you avoid classloading issue this way,
>> especially when the dependency is not designed for OSGi.
> 
> Um... not sure what you mean...?  Do you mean rebundling Neo4J before
> pulling it into karaf?  Either individually (*lots* of work, probably),
> or as a fat jar (less work if the maven dependencies of the top jar can
> be made to do the trick).
> 
>> Unfortunately, I wanted to create neo4j bundle at ServiceMix, but it's
>> not possible due to neo4j license.
> 
> Yeah, the licensing was why I didn't rebundle with maven in the first
> place.  I hoped the wrap protocol could do the trick...
> 


Re: Resolving a type from a wrapped jar file

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:

> why you don't just put this as private package. You will avoid class
> loading issue this way.

> In OSGi, not all is necessary an import. It could be a private package
> and/or embed dependency. It means the packages are embedded in the
> bundle. The bundle is "fat" but you avoid classloading issue this way,
> especially when the dependency is not designed for OSGi.

Um... not sure what you mean...?  Do you mean rebundling Neo4J before
pulling it into karaf?  Either individually (*lots* of work, probably),
or as a fat jar (less work if the maven dependencies of the top jar can
be made to do the trick).

> Unfortunately, I wanted to create neo4j bundle at ServiceMix, but it's
> not possible due to neo4j license.

Yeah, the licensing was why I didn't rebundle with maven in the first
place.  I hoped the wrap protocol could do the trick...


Re: Resolving a type from a wrapped jar file

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

why you don't just put this as private package. You will avoid class
loading issue this way.

In OSGi, not all is necessary an import. It could be a private package
and/or embed dependency. It means the packages are embedded in the
bundle. The bundle is "fat" but you avoid classloading issue this way,
especially when the dependency is not designed for OSGi.

Unfortunately, I wanted to create neo4j bundle at ServiceMix, but it's
not possible due to neo4j license.

Regards
JB

On 09/09/2018 20:16, Steinar Bang wrote:
>>>>>> Steinar Bang <sb...@dod.no>:
> 
>> My bundle, ie. the bundle containing the failing component, contains an
>> import-package for org.neo4j.graphdb.
> 
>> But the bundle where the error occurs, ie. wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-graphdb-api_3.4.7_neo4j-graphdb-api-3.4.7.jar
>> does *not* contain an import-package for org.neo4j.graphdb.
> 
>> Is there a way to force-add an import-package for a wrapped jar?
> 
> I did the following:
>  1. Exclude the offending dependency from the maven dependencies
>         <dependency>
>             <groupId>org.neo4j</groupId>
>             <artifactId>neo4j</artifactId>
>             <version>3.4.7</version>
>             <exclusions>
>                 <exclusion>
>                     <groupId>org.neo4j</groupId>
>                     <artifactId>neo4j-graphdb-api</artifactId>
>                 </exclusion>
>             </exclusions>
>         </dependency>
>         <dependency>
>             <groupId>org.neo4j</groupId>
>             <artifactId>neo4j-graphdb-api</artifactId>
>             <version>3.4.7</version>
>             <scope>provided</scope>
>         </dependency>
>         <dependency>
>             <groupId>org.neo4j</groupId>
>             <artifactId>neo4j-resource</artifactId>
>             <version>3.4.7</version>
>         </dependency>
>   2. Explictly specify the wrap'ed bundle in the template feature.xml,
>      adding the org.neo4j.graphdb to 
>         <bundle start-level="80">wrap:mvn:org.neo4j/neo4j-graphdb-api/3.4.7$Import-Package=org.neo4j.collection.primitive;resolution:=optional,org.neo4j.function;resolution:=optional,org.neo4j.helpers;resolution:=optional,org.neo4j.helpers.collection;resolution:=optional,org.neo4j.kernel.api.exceptions;resolution:=optional,org.neo4j.graphdb;resolution:=optional</bundle>
> 
> bundle:headers reported the wrapped mvn:org.neo4j/neo4j-graphdb-api to
> be importing org.neo4j.graphdb but I still got the exception when
> running the activator:
> ...
> Caused by: java.lang.ClassNotFoundException: org.neo4j.graphdb.ResourceIterable not found by wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-graphdb-api_3.4.7_neo4j-graphdb-api-3.4.7.jar_Import-Package_org.neo4j.collection.primitive_resolution__optional_org.neo4j.function_resolution__optional_org.neo4j.helpers_resolution__optional_org.neo4j.helpers.collection_resolution__optional_org.neo4j.kernel.api.exceptions_resolution__optional_org.neo4j.graphdb_resolution__optional [106]
> 
> Also bundle:capabilities on the wrapped mvn:org.neo4j/neo4j-resource/3.4.7
> shows the package as unused:
>  karaf@root()> bundle:capabilities 117
>  wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar [117] provides:
>  ---------------------------------------------------------------------------------------------------------
>  osgi.wiring.bundle; wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar 0.0.0 [UNUSED]
>  osgi.wiring.host; wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar 0.0.0 [UNUSED]
>  osgi.identity; wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar 0.0.0 [UNUSED]
>  osgi.wiring.package; org.neo4j.graphdb 0.0.0 [UNUSED]
>  karaf@root()>
> 

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: Resolving a type from a wrapped jar file

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> My bundle, ie. the bundle containing the failing component, contains an
> import-package for org.neo4j.graphdb.

> But the bundle where the error occurs, ie. wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-graphdb-api_3.4.7_neo4j-graphdb-api-3.4.7.jar
> does *not* contain an import-package for org.neo4j.graphdb.

> Is there a way to force-add an import-package for a wrapped jar?

I did the following:
 1. Exclude the offending dependency from the maven dependencies
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>3.4.7</version>
            <exclusions>
                <exclusion>
                    <groupId>org.neo4j</groupId>
                    <artifactId>neo4j-graphdb-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-graphdb-api</artifactId>
            <version>3.4.7</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-resource</artifactId>
            <version>3.4.7</version>
        </dependency>
  2. Explictly specify the wrap'ed bundle in the template feature.xml,
     adding the org.neo4j.graphdb to 
        <bundle start-level="80">wrap:mvn:org.neo4j/neo4j-graphdb-api/3.4.7$Import-Package=org.neo4j.collection.primitive;resolution:=optional,org.neo4j.function;resolution:=optional,org.neo4j.helpers;resolution:=optional,org.neo4j.helpers.collection;resolution:=optional,org.neo4j.kernel.api.exceptions;resolution:=optional,org.neo4j.graphdb;resolution:=optional</bundle>

bundle:headers reported the wrapped mvn:org.neo4j/neo4j-graphdb-api to
be importing org.neo4j.graphdb but I still got the exception when
running the activator:
...
Caused by: java.lang.ClassNotFoundException: org.neo4j.graphdb.ResourceIterable not found by wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-graphdb-api_3.4.7_neo4j-graphdb-api-3.4.7.jar_Import-Package_org.neo4j.collection.primitive_resolution__optional_org.neo4j.function_resolution__optional_org.neo4j.helpers_resolution__optional_org.neo4j.helpers.collection_resolution__optional_org.neo4j.kernel.api.exceptions_resolution__optional_org.neo4j.graphdb_resolution__optional [106]

Also bundle:capabilities on the wrapped mvn:org.neo4j/neo4j-resource/3.4.7
shows the package as unused:
 karaf@root()> bundle:capabilities 117
 wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar [117] provides:
 ---------------------------------------------------------------------------------------------------------
 osgi.wiring.bundle; wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar 0.0.0 [UNUSED]
 osgi.wiring.host; wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar 0.0.0 [UNUSED]
 osgi.identity; wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar 0.0.0 [UNUSED]
 osgi.wiring.package; org.neo4j.graphdb 0.0.0 [UNUSED]
 karaf@root()>


Re: Resolving a type from a wrapped jar file

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> The next problem is problem resolving a type from a wrapped jar file
> when activating the component:
> 2018-09-09T16:36:41,324 | ERROR | Thread-97        | karaf                            | 56 - no.priv.bang.neo4j.karaf - 1.0.0.SNAPSHOT | BundleComponentActivator : Bundle [56] Unexpected failure enabling component holder no.priv.bang.neo4j.karaf.Neo4jServer
> java.lang.NoClassDefFoundError: org/neo4j/graphdb/ResourceIterable
[snip!]
> Caused by: java.lang.ClassNotFoundException: org.neo4j.graphdb.ResourceIterable not found by wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-graphdb-api_3.4.7_neo4j-graphdb-api-3.4.7.jar [108]
> 	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1639) ~[?:?]
[snip!]

My bundle, ie. the bundle containing the failing component, contains an
import-package for org.neo4j.graphdb.

But the bundle where the error occurs, ie. wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-graphdb-api_3.4.7_neo4j-graphdb-api-3.4.7.jar
does *not* contain an import-package for org.neo4j.graphdb.

Is there a way to force-add an import-package for a wrapped jar?

Here are the output of bundle:headers for the various bundles.

 1. My bundle, ie. an actual bundle that contains the DS component that
    fails during start
     karaf@root()> bundle:headers no.priv.bang.neo4j.karaf

     neo4j karaf feature (56)
     ------------------------
     Bnd-LastModified = 1536510486935
     Build-Jdk = 1.8.0_181
     Built-By = sb
     Created-By = Apache Maven Bundle Plugin
     Manifest-Version = 1.0
     Service-Component = OSGI-INF/no.priv.bang.neo4j.karaf.Neo4jServer.xml
     Tool = Bnd-3.5.0.201709291849

     Bundle-Description = An apache karaf feature to load Neo4J into karaf and a bundle with a DS component to receive Neo4J config from karaf and start a Neo4J server inside karaf
     Bundle-ManifestVersion = 2
     Bundle-Name = neo4j karaf feature
     Bundle-SymbolicName = no.priv.bang.neo4j.karaf
     Bundle-Version = 1.0.0.SNAPSHOT

     Provide-Capability =
             osgi.service;objectClass:List<String>=org.neo4j.graphdb.GraphDatabaseService
     Require-Capability =
             osgi.extender;filter:=(&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0))),
             osgi.service;effective:=active;filter:=(objectClass=org.apache.karaf.system.SystemService),
             osgi.service;effective:=active;filter:=(objectClass=org.osgi.service.log.LogService),
             osgi.ee;filter:=(&(osgi.ee=JavaSE)(version=1.8))

     Import-Package =
             org.apache.karaf.system;version="[4.1,5)",
             org.neo4j.graphdb,
             org.neo4j.graphdb.event,
             org.neo4j.graphdb.factory,
             org.neo4j.graphdb.index,
             org.neo4j.graphdb.schema,
             org.neo4j.graphdb.traversal,
             org.osgi.service.log;version="[1.3,2)"


 2. The bundle containing the missing class
     karaf@root()> bundle:headers 120

     wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar (120)
     -----------------------------------------------------------------------------------------------
     Automatic-Module-Name = org.neo4j.graphdb.resourse
     Bnd-LastModified = 1536510664853
     Build-Jdk = 1.8.0_181
     Built-By = teamcity
     Created-By = 1.8.0_181 (Oracle Corporation)
     Generated-By-Ops4j-Pax-From = wrap:file:/home/sb/.m2/repository/org/neo4j/neo4j-resource/3.4.7/neo4j-resource-3.4.7.jar
     Implementation-Title = Neo4j - Resource interface
     Implementation-URL = http://components.neo4j.org/neo4j-resource/3.4.7
     Implementation-Vendor = The Neo4j Graph Database Project
     Implementation-Vendor-Id = org.neo4j
     Implementation-Version = 3.4.7
     Manifest-Version = 1.0
     Originally-Created-By = Apache Maven 3.5.4
     Tool = Bnd-2.3.0.201405100607
     Url = https://neo4j.com/

     Bundle-ManifestVersion = 2
     Bundle-Name = wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar
     Bundle-SymbolicName = wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar
     Bundle-Version = 0

     Require-Capability =
             osgi.ee;filter:=(&(osgi.ee=JavaSE)(version=1.8))

     Export-Package =
             org.neo4j.graphdb

 3. The bundle where the error occurs
     karaf@root()> bundle:headers 108

     wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-graphdb-api_3.4.7_neo4j-graphdb-api-3.4.7.jar (108)
     -----------------------------------------------------------------------------------------------------
     Automatic-Module-Name = org.neo4j.graphdb
     Bnd-LastModified = 1536510663369
     Build-Jdk = 1.8.0_181
     Built-By = teamcity
     Created-By = 1.8.0_181 (Oracle Corporation)
     Generated-By-Ops4j-Pax-From = wrap:file:/home/sb/.m2/repository/org/neo4j/neo4j-graphdb-api/3.4.7/neo4j-graphdb-api-3.4.7.jar
     Implementation-Title = Neo4j - Graph Database API
     Implementation-URL = http://components.neo4j.org/neo4j-graphdb-api/3.4.7
     Implementation-Vendor = The Neo4j Graph Database Project
     Implementation-Vendor-Id = org.neo4j
     Implementation-Version = 3.4.7
     Manifest-Version = 1.0
     Originally-Created-By = Apache Maven 3.5.4
     Tool = Bnd-2.3.0.201405100607
     Url = https://neo4j.com/

     Bundle-ManifestVersion = 2
     Bundle-Name = wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-graphdb-api_3.4.7_neo4j-graphdb-api-3.4.7.jar
     Bundle-SymbolicName = wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-graphdb-api_3.4.7_neo4j-graphdb-api-3.4.7.jar
     Bundle-Version = 0

     Require-Capability =
             osgi.ee;filter:=(&(osgi.ee=JavaSE)(version=1.8))

     Export-Package =
             org.neo4j.graphdb;uses:="org.neo4j.graphdb.event,org.neo4j.graphdb.index,org.neo4j.graphdb.schema,org.neo4j.graphdb.traversal,org.neo4j.kernel.api.exceptions",
             org.neo4j.graphdb.config,
             org.neo4j.graphdb.event;uses:=org.neo4j.graphdb,
             org.neo4j.graphdb.impl;uses:="org.neo4j.graphdb,org.neo4j.graphdb.traversal",
             org.neo4j.graphdb.impl.traversal;uses:="org.neo4j.graphdb,org.neo4j.graphdb.traversal",
             org.neo4j.graphdb.index;uses:=org.neo4j.graphdb,
             org.neo4j.graphdb.schema;uses:="org.neo4j.graphdb,org.neo4j.graphdb.index",
             org.neo4j.graphdb.security;uses:="org.neo4j.graphdb.config,org.neo4j.kernel.api.exceptions",
             org.neo4j.graphdb.spatial,
             org.neo4j.graphdb.traversal;uses:="org.neo4j.graphdb,org.neo4j.graphdb.impl.traversal"
     Import-Package =
             org.neo4j.collection.primitive;resolution:=optional,
             org.neo4j.function;resolution:=optional,
             org.neo4j.helpers;resolution:=optional,
             org.neo4j.helpers.collection;resolution:=optional,
             org.neo4j.kernel.api.exceptions;resolution:=optional


Resolving a type from a wrapped jar file (Was: Problems accessing SystemMBean from a DS component)

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> Maybe I would be better off trying to inject the SystemService? (if that
> does what I need to do? Yep, it appears to have the same methods, more
> or less... [1])

Using SystemService was successful.  Now I get the service injection.

The next problem is problem resolving a type from a wrapped jar file
when activating the component:
2018-09-09T16:36:41,324 | ERROR | Thread-97        | karaf                            | 56 - no.priv.bang.neo4j.karaf - 1.0.0.SNAPSHOT | BundleComponentActivator : Bundle [56] Unexpected failure enabling component holder no.priv.bang.neo4j.karaf.Neo4jServer
java.lang.NoClassDefFoundError: org/neo4j/graphdb/ResourceIterable
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:?]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:?]
	at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[?:?]
	at org.apache.felix.scr.impl.inject.BindMethod.getServiceObjectAssignableMethod(BindMethod.java:459) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.inject.BindMethod.doFindMethod(BindMethod.java:188) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.inject.BaseMethod.findMethod(BaseMethod.java:175) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.inject.BaseMethod.access$400(BaseMethod.java:39) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.inject.BaseMethod$NotResolved.resolve(BaseMethod.java:593) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.inject.BaseMethod$NotResolved.methodExists(BaseMethod.java:615) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.inject.BaseMethod.methodExists(BaseMethod.java:520) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.inject.BindMethod.getServiceObject(BindMethod.java:648) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.manager.DependencyManager.getServiceObject(DependencyManager.java:2201) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.manager.DependencyManager$SingleStaticCustomizer.prebind(DependencyManager.java:1118) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.manager.DependencyManager.prebind(DependencyManager.java:1520) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.collectDependencies(AbstractComponentManager.java:1006) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:859) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:749) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:675) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:430) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:657) ~[60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:341) [60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:390) [60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.Activator.access$200(Activator.java:54) [60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:265) [60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:254) [60:org.apache.felix.scr:2.0.12]
	at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:227) [60:org.apache.felix.scr:2.0.12]
	at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:482) [?:?]
	at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:415) [?:?]
	at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232) [?:?]
	at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444) [?:?]
	at org.apache.felix.framework.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:915) [?:?]
	at org.apache.felix.framework.EventDispatcher.fireEventImmediately(EventDispatcher.java:834) [?:?]
	at org.apache.felix.framework.EventDispatcher.fireBundleEvent(EventDispatcher.java:516) [?:?]
	at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4579) [?:?]
	at org.apache.felix.framework.Felix.startBundle(Felix.java:2174) [?:?]
	at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998) [?:?]
	at org.apache.karaf.bundle.core.internal.BundleWatcherImpl.run(BundleWatcherImpl.java:125) [22:org.apache.karaf.bundle.core:4.1.5]
	at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.lang.ClassNotFoundException: org.neo4j.graphdb.ResourceIterable not found by wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-graphdb-api_3.4.7_neo4j-graphdb-api-3.4.7.jar [108]
	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1639) ~[?:?]
	at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80) ~[?:?]
	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2053) ~[?:?]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
	at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1414) ~[?:?]
	at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1660) ~[?:?]
	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1590) ~[?:?]
	at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80) ~[?:?]
	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2053) ~[?:?]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
	... 38 more

org.neo4j.graphdb.ResourceIterable is in mvn:org.neo4j/neo4j-resource/3.4.7 which is a transitive dependency of mvn:org.neo4j/neo4j-graphdb-api/3.4.7:
mvn dependency:tree
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building neo4j karaf feature 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ neo4j.karaf ---
[INFO] no.priv.bang.neo4j.karaf:neo4j.karaf:bundle:1.0.0-SNAPSHOT
[INFO] +- org.neo4j:neo4j:jar:3.4.7:compile
[INFO] |  +- org.neo4j:neo4j-kernel:jar:3.4.7:compile
[INFO] |  |  +- org.neo4j:neo4j-graphdb-api:jar:3.4.7:compile
[INFO] |  |  |  \- org.neo4j:neo4j-resource:jar:3.4.7:compile
...

Both jar files ends up as wrap'd jar files in the feature:
    <feature name="neo4j-server" description="neo4j karaf feature" version="1.0.0.SNAPSHOT">
        <details>An apache karaf feature to load Neo4J into karaf and a bundle with a DS component to receive Neo4J config from karaf and start a Neo4J server inside karaf</details>
        <feature prerequisite="false" dependency="false">scr</feature>
        <feature prerequisite="true" dependency="false">wrap</feature>
        <bundle start-level="80">mvn:no.priv.bang.neo4j.karaf/neo4j.karaf/1.0.0-SNAPSHOT</bundle>
        <bundle start-level="80">wrap:mvn:org.neo4j/neo4j/3.4.7</bundle>
        <bundle start-level="80">wrap:mvn:org.neo4j/neo4j-kernel/3.4.7</bundle>
        <bundle start-level="80">wrap:mvn:org.neo4j/neo4j-graphdb-api/3.4.7</bundle>
        <bundle start-level="80">wrap:mvn:org.neo4j/neo4j-resource/3.4.7</bundle>
        <bundle start-level="80">wrap:mvn:org.neo4j/neo4j-procedure-api/3.4.7</bundle>
        ...

My bundle imports the package org.neo4j.graphdb (without a version number):
Import-Package: org.apache.karaf.system.management;version="[4.1,5)",o
 rg.neo4j.graphdb,org.neo4j.graphdb.event,org.neo4j.graphdb.factory,or
 g.neo4j.graphdb.index,org.neo4j.graphdb.schema,org.neo4j.graphdb.trav
 ersal,org.osgi.service.log;version="[1.3,2)"

The wrapped jar exports the package org.neo4j.graphdb but have no users
of that package:
karaf@root()> bundle:list | grep resource
120 │ Active │  80 │ 0                                   │ wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar
karaf@root()> bundle:capabilities 120
wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar [120] provides:
---------------------------------------------------------------------------------------------------------
osgi.wiring.bundle; wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar 0.0.0 [UNUSED]
osgi.wiring.host; wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar 0.0.0 [UNUSED]
osgi.identity; wrap_file__home_sb_.m2_repository_org_neo4j_neo4j-resource_3.4.7_neo4j-resource-3.4.7.jar 0.0.0 [UNUSED]
osgi.wiring.package; org.neo4j.graphdb 0.0.0 [UNUSED]
karaf@root()>

Do I need to statically reference something in the org.neo4j.graphdb
package, to get things to work?


Re: Problems accessing SystemMBean from a DS component

Posted by Francois Papon <fr...@openobject.fr>.
Hi Steinar,

Are you shure about the @Reference ? In your example code, the reference
is on a LogService.

regards,

François Papon
fpapon@apache.org

Le 09/09/2018 à 18:05, Steinar Bang a écrit :
>>>>>> Steinar Bang <sb...@dod.no>:
>> Platform: debian 9.5 "stretch", amd64
>>           openjdk-8-jdk 8u181-b13-1~deb9u1
>>           karaf 4.1.5
>> (Note: This is a project very much in the start phase so I haven't pushed
>> anything to github yet)
>> I'm trying to inject a SystemMBean into a DS component.  When I try
>> this, loading the feature holding the component, fails with an error
>> message:
>>  karaf@root()> feature:repo-add mvn:no.priv.bang.neo4j.karaf/neo4j-karaf/LATEST/xml/features
>>  Adding feature url mvn:no.priv.bang.neo4j.karaf/neo4j-karaf/LATEST/xml/features
>>  karaf@root()> feature:install neo4j-server
>>  Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=neo4j-server; type=karaf.feature; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; filter:="(&(osgi.identity=neo4j-server)(type=karaf.feature)(version>=1.0.0.SNAPSHOT)(version<=1.0.0.SNAPSHOT))" [caused by: Unable to resolve neo4j-server/1.0.0.SNAPSHOT: missing requirement [neo4j-server/1.0.0.SNAPSHOT] osgi.identity; osgi.identity=no.priv.bang.neo4j.karaf; type=osgi.bundle; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve no.priv.bang.neo4j.karaf/1.0.0.SNAPSHOT: missing requirement [no.priv.bang.neo4j.karaf/1.0.0.SNAPSHOT] osgi.service; filter:="(objectClass=org.apache.karaf.system.management.SystemMBean)"; effective:=active]]
>>  karaf@root()>
> If I remove the
>     @Reference
>     public void setLogservice(LogService logservice) {
>         this.logservice = logservice;
>     }
>
> then my feature loads:
> karaf@root()> feature:repo-add mvn:no.priv.bang.neo4j.karaf/neo4j-karaf/LATEST/xml/features
> Adding feature url mvn:no.priv.bang.neo4j.karaf/neo4j-karaf/LATEST/xml/features
> karaf@root()> feature:install neo4j-server
> karaf@root()>
>
> So I guess this means that the above message is because the service
> dependency isn't satisfied...?
>
> But why isn't the ServiceMBean service dependency satisfied from this?
>  karaf@root()> bundle:capabilities org.apache.karaf.system.core
>  org.apache.karaf.system.core [46] provides:
>  -------------------------------------------
>  osgi.wiring.bundle; org.apache.karaf.system.core 4.1.5 [UNUSED]
>  osgi.wiring.host; org.apache.karaf.system.core 4.1.5 [UNUSED]
>  osgi.identity; org.apache.karaf.system.core 4.1.5 [UNUSED]
>  osgi.wiring.package; org.apache.karaf.system 4.1.5 [UNUSED]
>  osgi.wiring.package; org.apache.karaf.system.management 4.1.5 [UNUSED]
>  service; [org.apache.karaf.system.SystemService] with properties:
>     service.bundleid = 46
>     service.id = 103
>     service.scope = singleton
>     Used by:
>        org.apache.karaf.system.core [46]
>  service; [org.apache.karaf.system.management.SystemMBean, javax.management.DynamicMBean, javax.management.MBeanRegistration] with properties:
>     jmx.objectname = org.apache.karaf:type=system,name=root
>     service.bundleid = 46
>     service.id = 104
>     service.scope = singleton
>     Used by:
>        org.apache.aries.jmx.whiteboard [18]
>  karaf@root()>
>
> Maybe I would be better off trying to inject the SystemService? (if that
> does what I need to do? Yep, it appears to have the same methods, more
> or less... [1])
>
> References
> [1] <https://github.com/apache/karaf/blob/master/system/src/main/java/org/apache/karaf/system/SystemService.java>
>



Re: Problems accessing SystemMBean from a DS component

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

> Platform: debian 9.5 "stretch", amd64
>           openjdk-8-jdk 8u181-b13-1~deb9u1
>           karaf 4.1.5

> (Note: This is a project very much in the start phase so I haven't pushed
> anything to github yet)

> I'm trying to inject a SystemMBean into a DS component.  When I try
> this, loading the feature holding the component, fails with an error
> message:
>  karaf@root()> feature:repo-add mvn:no.priv.bang.neo4j.karaf/neo4j-karaf/LATEST/xml/features
>  Adding feature url mvn:no.priv.bang.neo4j.karaf/neo4j-karaf/LATEST/xml/features
>  karaf@root()> feature:install neo4j-server
>  Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=neo4j-server; type=karaf.feature; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; filter:="(&(osgi.identity=neo4j-server)(type=karaf.feature)(version>=1.0.0.SNAPSHOT)(version<=1.0.0.SNAPSHOT))" [caused by: Unable to resolve neo4j-server/1.0.0.SNAPSHOT: missing requirement [neo4j-server/1.0.0.SNAPSHOT] osgi.identity; osgi.identity=no.priv.bang.neo4j.karaf; type=osgi.bundle; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve no.priv.bang.neo4j.karaf/1.0.0.SNAPSHOT: missing requirement [no.priv.bang.neo4j.karaf/1.0.0.SNAPSHOT] osgi.service; filter:="(objectClass=org.apache.karaf.system.management.SystemMBean)"; effective:=active]]
>  karaf@root()>

If I remove the
    @Reference
    public void setLogservice(LogService logservice) {
        this.logservice = logservice;
    }

then my feature loads:
karaf@root()> feature:repo-add mvn:no.priv.bang.neo4j.karaf/neo4j-karaf/LATEST/xml/features
Adding feature url mvn:no.priv.bang.neo4j.karaf/neo4j-karaf/LATEST/xml/features
karaf@root()> feature:install neo4j-server
karaf@root()>

So I guess this means that the above message is because the service
dependency isn't satisfied...?

But why isn't the ServiceMBean service dependency satisfied from this?
 karaf@root()> bundle:capabilities org.apache.karaf.system.core
 org.apache.karaf.system.core [46] provides:
 -------------------------------------------
 osgi.wiring.bundle; org.apache.karaf.system.core 4.1.5 [UNUSED]
 osgi.wiring.host; org.apache.karaf.system.core 4.1.5 [UNUSED]
 osgi.identity; org.apache.karaf.system.core 4.1.5 [UNUSED]
 osgi.wiring.package; org.apache.karaf.system 4.1.5 [UNUSED]
 osgi.wiring.package; org.apache.karaf.system.management 4.1.5 [UNUSED]
 service; [org.apache.karaf.system.SystemService] with properties:
    service.bundleid = 46
    service.id = 103
    service.scope = singleton
    Used by:
       org.apache.karaf.system.core [46]
 service; [org.apache.karaf.system.management.SystemMBean, javax.management.DynamicMBean, javax.management.MBeanRegistration] with properties:
    jmx.objectname = org.apache.karaf:type=system,name=root
    service.bundleid = 46
    service.id = 104
    service.scope = singleton
    Used by:
       org.apache.aries.jmx.whiteboard [18]
 karaf@root()>

Maybe I would be better off trying to inject the SystemService? (if that
does what I need to do? Yep, it appears to have the same methods, more
or less... [1])

References
[1] <https://github.com/apache/karaf/blob/master/system/src/main/java/org/apache/karaf/system/SystemService.java>