Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

OSGI R7 annotation

Avatar

Level 3

Hi,

I have created a project using AEM Archetype 17 and followed this article. I am able to use other osgi R7 annotations like @ServiceDescription or @ServiceVendor. But I am not able to use @Activate on configuration like this:

@Activate

private MyServiceConfiguration config;

I am getting error '@Activate not applicable to field' in intelliJ idea and while maven build I am getting error 'annotation type not applicable to this kind of declaration'.

12 Replies

Avatar

Level 3

Feike Visser​ Could you please have a look. I guess its your article. I am using AEM 6.4, jdk 1.8, Maven 3.5.4.

Avatar

Community Advisor

DIPEN,

   Sorry. Feike is no more with us. Will check this soon

Thanks

Veena

Avatar

Employee Advisor

The error message is quite clear: You cannot annotate a field with the @Activate method, but only a method.

Jörg

Avatar

Community Advisor

@Dipen This might be helpful

https://blog.osgi.org/2018/03/osgi-r7-highlights-declarative-services.html

Activation Fields

In addition to supporting injecting activation objects using constructor injection, and also method injection via the activate method, DS 1.4 adds support for field injection of activation objects. A field of the type of an activation object can be annotated with Activate and SCR will inject the activation object into the field after object construction.

@Activate private ComponentContext context;
@Activate private BundleContext bc;

@Activate private Map<String,Object> componentProps;

@Activate private Props props;

Avatar

Community Advisor

check the version of maven-bundle-plugin (should be 4.1.0) or bnd plugin (should be 4.1) is the root cause?  Archetype 17 should have generated R7 versions but no harm in validating the effective pom/versions

Avatar

Community Advisor

Guys,

The issue is, there are more than one jar which has Activate class, due to this the class which support @Actiavate annotation with field is not getting used.

To fix this issue, just update below dependency version to 7 in parent POM. and rebuild the project. Hope this will help.

Let me know if further issue, I am able to successfully build the project using R7 annotation.

     <dependency>

                <groupId>org.osgi</groupId>

                <artifactId>osgi.cmpn</artifactId>

                <version>7.0.0</version>

                <scope>provided</scope>

            </dependency>

Avatar

Level 3

Arun Patidar

With the changes to osgi.cmpn dependency version, build is successful but bundle is getting installed state. org.osgi.service.event is not resolved. org.osgi.service.event is imported as [1.4,2) whereas in AEM 6.4 version 1.3.1 is available which is exported by Apache Felix EventAdmin bundle.

So I am able to build but not deploy.

Avatar

Community Advisor

Hi Add below dependency as well in parent and core pom

<dependency>

<groupId>org.osgi</groupId>

<artifactId>org.osgi.compendium</artifactId>

<version>5.0.0</version>

<scope>provided</scope>

</dependency>

Please let me know, I can share my package.

Edit:

you should use below dependency instead of above (org.osgi.compendium)

<dependency> 

    <groupId>org.apache.felix</groupId> 

    <artifactId>org.apache.felix.eventadmin</artifactId> 

    <version>1.4.10</version> 

    <scope>provided</scope> 

</dependency>

Avatar

Level 8

reordering the dependencies in core pom worked for me. I faced the same issue.

CORE POM

<dependencies>

<dependency>

  <groupId>org.osgi</groupId>

  <artifactId>org.osgi.service.component</artifactId>

  </dependency>

  <dependency>

  <groupId>org.osgi</groupId>

  <artifactId>org.osgi.service.component.annotations</artifactId>

</dependency>

<dependency>

  <groupId>org.osgi</groupId>

  <artifactId>org.osgi.service.metatype.annotations</artifactId>

</dependency>

        <!-- OSGi Dependencies -->

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.core</artifactId>

        </dependency>

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.cmpn</artifactId>

        </dependency>

        <dependency>

            <groupId>org.osgi</groupId>

            <artifactId>osgi.annotation</artifactId>

        </dependency>

.......................................

PROJECT POM:

add the following deps as given in articles:

<dependency>

  <groupId>org.osgi</groupId>

  <artifactId>org.osgi.service.component.annotations</artifactId>

  <version>1.4.0</version>

  <scope>provided</scope>

</dependency>

<dependency>

  <groupId>org.osgi</groupId>

  <artifactId>org.osgi.annotation</artifactId>

  <version>6.0.0</version>

  <scope>provided</scope>

</dependency>

<dependency>

  <groupId>org.osgi</groupId>

  <artifactId>org.osgi.service.metatype.annotations</artifactId>

  <version>1.4.0</version>

  <scope>provided</scope>

</dependency>

<dependency>

  <groupId>org.osgi</groupId>

  <artifactId>org.osgi.service.component</artifactId>

  <version>1.4.0</version>

  <scope>provided</scope>

</dependency>

Avatar

Employee

This is the right solution and it worked as mentioned by changing the order in core pom.

Avatar

Level 3

Arun Patidar

Now I am able to build, deploy but facing another issue. Junit testcases are not running from intelliJ. I am using junit5 with AEM mock. Previously it used to work. Although while build testcases running fine but I am not able to run individually test case by right click.

Please let me know if you faced this issue.

Avatar

Level 3

Any update on how to running Junit test cases in intelliJ ? With @Activate annotation on fields, Junit is not running in IntelliJ Idea.