4

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 be able to use the GoogleMaps API in my component. So I add the dependency for it in hometest.core/pom.xml

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

I've also added everything to the _exportcontents in hometest.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>

I then import com.google.maps.model.GeocodingResult into HelloServiceProxy.java as shown below:

enter image description here

I install the package to local instance of aem using mvn clean install -PautoInstallPackage

However, when I try to add the 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 to a package

Below is screenshot of the error:

enter image description here

Update 1

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

  • in core/pom.xml added configuration settings 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 like this:

    <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 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
Anthony
  • 33,838
  • 42
  • 169
  • 278
  • I've seen this problem before. Sometimes a superficial change to force the recompilation of the view or ui helps. I don't have great understanding about it. But it could be that the dependency in core and the ui package is trying to use a service that is not registered when the ui jsp gets compiled – Cris Rockwell Jul 14 '15 at 15:21
  • @ChristopherRockwell how did you solve it? – Anthony Jul 14 '15 at 17:34
  • You may be interested in a question I recently posted http://stackoverflow.com/questions/31191299/google-client-api-in-osgi but I didn't export the jars, only embedded. So they can only be used within the service/core bundle. .... Additionally in regards about "Only a type can be imported." I've 'solved' that before by redeploying just the view, and in another case just saving a whitespace change in the JSP (forcing a recompile). But if it were me, I would embed (not export) the jars and use them within the same bundle if possible, even thou that's not really the osgi way – Cris Rockwell Jul 14 '15 at 17:53
  • were you able to resolve this? – Dileepa Mar 03 '16 at 12:57

1 Answers1

0

The error indicates that the classes from google-maps-services bundle are not available to the hometest.core bundle. It might very well be that embedding bundles does not work at this point.

Can you try deploying a separate bundle which embeds google-maps-services and see if that works?

Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
  • I tried another bundle and have updated what I did in the question. Error is the same as before.. – Anthony Jul 14 '15 at 12:13
  • Can you open up the jar contents of hometest bundle and see if it's manifest.mf has google-maps-services packages listed in its "Import-Package" header. If its there with a proper version, then check if the same packages are present in the export-package section of google's bundle. If this does not work, give a try for attribute of maven-bundle-plugin instead of using . – Shailesh Pratapwar Jul 15 '15 at 04:06
  • @Anthony were you able to clear the jsp compilation error? – Cris Rockwell Jul 23 '15 at 13:18
  • Sorry, I missed the update. What I mean was to deploy another bundle using mvn sling:install or the Felix Web Console and try again. – Robert Munteanu Aug 04 '15 at 10:44