How to import class from 3rd party jar file into OSGi component

I am using https://eclipse.adobe.com/aem/dev-tools/ to create a project. Once created, I have the following structure in eclipse:

enter image description here

I want to use the GoogleMaps API in my component. So I add a dependency for it inhometest.core/pom.xml

<dependency>
    <groupId>com.google.maps</groupId>
    <artifactId>google-maps-services</artifactId>
    <version>0.1.7</version>
    <scope>compile</scope>
</dependency>

      

I also added everything to _exportcontents

inhometest.core/pom.xml

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                    <Embed-Directory>OSGI-INF/lib</Embed-Directory>
                    <_exportcontents>
                                    *
                    </_exportcontents>
                </instructions>
            </configuration>
        </plugin>

      

Then I import com.google.maps.model.GeocodingResult

in HelloServiceProxy.java

as shown below:

enter image description here

I am installing a package to a local aem instance using mvn clean install -PautoInstallPackage

However, when I try to add a component to the page, I get the following error:

java.lang.Error: unresolved compilation problem: only a type can be imported. com.google.maps.model.GeocodingResult resolves package

Below is a screenshot of the error:

enter image description here

Update 1

I started with another brand new AEM project and did the following things:

  • added config settings to core / pom.xml for maven-bundle-plugin

    like this

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
            <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
            <Embed-Directory>OSGI-INF/lib</Embed-Directory>
            <_exportcontents>
             *
            </_exportcontents>
            </instructions>
            </configuration>
        </plugin>
    
          

  • Added Google Maps dependency as follows:

    <dependency>
    <groupId>com.google.maps</groupId>
    <artifactId>google-maps-services</artifactId>
    <version>0.1.7</version>
    <scope>compile</scope>
    </dependency>
    
          

  • deployed with this mvn clean install -PautoInstallPackage

When I try to add a component to the page, I get errors:

java.lang.Error: Unresolved compilation problems: 
    Only a type can be imported. com.google.maps.model.GeocodingResult resolves to a package
    Only a type can be imported. org.demo.anothertest.core.HelloService resolves to a package
    HelloService cannot be resolved to a type
    HelloService cannot be resolved to a type

      

+3


source to share


1 answer


The error indicates that the classes from the package are google-maps-services

not available for the package hometest.core

. It is possible that the embedding of beams is not working at the moment.



Can you try expanding the separate package that inserts google-maps-services

and see if that works?

0


source







All Articles