Expand my Community achievements bar.

SOLVED

Accessing method from custom OSGi Service

Avatar

Level 5

I'm trying to access a method from a custom OSGi service I've built from a servlet.

How do I go about this with dependencies and initiating the variable from my servlet?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Yeah - the trick here you need to put the JAR that contains the Service (the Java Classes) - into your local Maven respository. THIs one took me too the first time i did this. Since the JAR is not in Adobe Maven Repo - how does Maven do it.

The answer is here: 

Upload the Jasper Urber OSGi bundle to your local Maven repository


You need to upload the  OSGi bundle to your local Maven repository. The reason is because the AEM custom service that is built uses the Jasper Reports API exposed in this OSGi bundle. 

As a result, when the AEM Service is build with a Maven 10 Archetype, Maven must be able to resolve all import statements (and Java logic) that use the Jasper Reports API such as these.

In order to resolve the Jasper Reports API within an AEM service, the Urber JasperReports JAR file must be located in the Maven repository. You can upload the Urber JAR to Maven by using this Maven command: 

mvn install:install-file -Dfile=C:/JasperReports/plugins/JasperAEMUrber_1.0.0.jar -DgroupId=com.foo.reports -DartifactId=jrurbersrt1.0 -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true

Notice that you must specify the location of the Urber JAR file in the -Dfile argument. Also notice that you specify the Dgroup and DartifactID values. Once you upload the JAR to Maven using this command, you can reference this JAR file using this Dependency.

<groupId>com.foo.reports</groupId>
<artifactId>jrurbersrt1.0</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\Users\scottm\.m2\repository\com\foo\reports\jrurbersrt1.0\1.0\jrurbersrt1.0-1.0.jar</systemPath>
</dependency>

Notice that scope element is system and systemPath references the location of the JAR file in the repository. (This dependency is used later in this article to build the AEM service) 

Reference it is the POM

In the following POM file, notice the dependency that references the custom Urber file.

<groupId>com.foo.reports</groupId>
<artifactId>jrurbersrt1.0</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\Users\scottm\.m2\repository\com\foo\reports\jrurbersrt1.0\1.0\jrurbersrt1.0-1.0.jar</systemPath>
</dependency>

Make sure you change the system path to point to the location in your Maven repository where the Jasper Urber JAR file is located.

<dependency>
            <groupId>com.foo.reports</groupId>
            <artifactId>jrurbersrt1.0</artifactId>
            <version>1.0</version>
            <scope>system</scope>
             <systemPath>C:\Users\scottm\.m2\repository\com\foo\reports\jrurbersrt1.0\1.0\jrurbersrt1.0-1.0.jar</systemPath>
        </dependency>

View solution in original post

3 Replies

Avatar

Level 10

If you have an OSGi service that exposes method A - you can use dependency injection and get an instance of that service from within your servlet. then all mehtod A

Avatar

Level 5

smacdonald2008 wrote...

If you have an OSGi service that exposes method A - you can use dependency injection and get an instance of that service from within your servlet. then all mehtod A

 


I understand you can use @Reference correct?
How would the dependency look on my servlet's POM file?

I'm getting an error everytime I'm trying to build bundle through maven. Sorry first time for this use case.

Lets say service is named SampleService in package com.foo.bar

Avatar

Correct answer by
Level 10

Yeah - the trick here you need to put the JAR that contains the Service (the Java Classes) - into your local Maven respository. THIs one took me too the first time i did this. Since the JAR is not in Adobe Maven Repo - how does Maven do it.

The answer is here: 

Upload the Jasper Urber OSGi bundle to your local Maven repository


You need to upload the  OSGi bundle to your local Maven repository. The reason is because the AEM custom service that is built uses the Jasper Reports API exposed in this OSGi bundle. 

As a result, when the AEM Service is build with a Maven 10 Archetype, Maven must be able to resolve all import statements (and Java logic) that use the Jasper Reports API such as these.

In order to resolve the Jasper Reports API within an AEM service, the Urber JasperReports JAR file must be located in the Maven repository. You can upload the Urber JAR to Maven by using this Maven command: 

mvn install:install-file -Dfile=C:/JasperReports/plugins/JasperAEMUrber_1.0.0.jar -DgroupId=com.foo.reports -DartifactId=jrurbersrt1.0 -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true

Notice that you must specify the location of the Urber JAR file in the -Dfile argument. Also notice that you specify the Dgroup and DartifactID values. Once you upload the JAR to Maven using this command, you can reference this JAR file using this Dependency.

<groupId>com.foo.reports</groupId>
<artifactId>jrurbersrt1.0</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\Users\scottm\.m2\repository\com\foo\reports\jrurbersrt1.0\1.0\jrurbersrt1.0-1.0.jar</systemPath>
</dependency>

Notice that scope element is system and systemPath references the location of the JAR file in the repository. (This dependency is used later in this article to build the AEM service) 

Reference it is the POM

In the following POM file, notice the dependency that references the custom Urber file.

<groupId>com.foo.reports</groupId>
<artifactId>jrurbersrt1.0</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\Users\scottm\.m2\repository\com\foo\reports\jrurbersrt1.0\1.0\jrurbersrt1.0-1.0.jar</systemPath>
</dependency>

Make sure you change the system path to point to the location in your Maven repository where the Jasper Urber JAR file is located.

<dependency>
            <groupId>com.foo.reports</groupId>
            <artifactId>jrurbersrt1.0</artifactId>
            <version>1.0</version>
            <scope>system</scope>
             <systemPath>C:\Users\scottm\.m2\repository\com\foo\reports\jrurbersrt1.0\1.0\jrurbersrt1.0-1.0.jar</systemPath>
        </dependency>