OSGI R7 annotation | Community
Skip to main content
DIPEN_SEN_
Level 3
March 25, 2019

OSGI R7 annotation

  • March 25, 2019
  • 9 replies
  • 18959 views

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'.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

9 replies

DIPEN_SEN_
Level 3
March 25, 2019

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.

VeenaVikraman
Community Advisor
Community Advisor
March 25, 2019

DIPEN,

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

Thanks

Veena

joerghoh
Adobe Employee
Adobe Employee
March 25, 2019

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

Jörg

BrijeshYadav
Level 5
March 26, 2019

@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;

Gaurav-Behl
Level 10
March 26, 2019

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

arunpatidar
Community Advisor
Community Advisor
March 26, 2019

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>

Arun Patidar
DIPEN_SEN_
Level 3
March 27, 2019

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.

arunpatidar
Community Advisor
Community Advisor
March 27, 2019

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>

Arun Patidar
Hemant_arora
Level 8
March 28, 2019

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>

venkat_krishnat
Adobe Employee
Adobe Employee
April 17, 2019

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

DIPEN_SEN_
Level 3
March 29, 2019

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.

DIPEN_SEN_
Level 3
May 20, 2019

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