DIPEN1
DIPEN1
25-03-2019
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'.
DIPEN1
DIPEN1
25-03-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.
Veena_Vikram
MVP
Veena_Vikram
MVP
25-03-2019
DIPEN,
Sorry. Feike is no more with us. Will check this soon
Thanks
Veena
Jörg_Hoh
Employee
Jörg_Hoh
Employee
25-03-2019
The error message is quite clear: You cannot annotate a field with the @Activate method, but only a method.
Jörg
BrijeshYadav
BrijeshYadav
26-03-2019
@Dipen This might be helpful
https://blog.osgi.org/2018/03/osgi-r7-highlights-declarative-services.html
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
MVP
Gaurav-Behl
MVP
26-03-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
Arun_Patidar
MVP
Arun_Patidar
MVP
26-03-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>
DIPEN1
DIPEN1
27-03-2019
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.
Arun_Patidar
MVP
Arun_Patidar
MVP
27-03-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>
Hemant_arora
Hemant_arora
28-03-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>