Java 如何从OSGi组件中的第三方jar文件导入类

Java 如何从OSGi组件中的第三方jar文件导入类,java,maven,osgi,aem,aem-developer-tools,Java,Maven,Osgi,Aem,Aem Developer Tools,我正在使用创建一个项目。创建后,我在eclipse中拥有以下结构: 我希望能够在我的组件中使用GoogleMaps API。因此,我在hometest.core/pom.xml <dependency> <groupId>com.google.maps</groupId> <artifactId>google-maps-services</artifactId> <version>0.1.7<

我正在使用创建一个项目。创建后,我在eclipse中拥有以下结构:

我希望能够在我的组件中使用GoogleMaps API。因此,我在
hometest.core/pom.xml

<dependency>
    <groupId>com.google.maps</groupId>
    <artifactId>google-maps-services</artifactId>
    <version>0.1.7</version>
    <scope>compile</scope>
</dependency>
        <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>
然后我将
com.google.maps.model.GeocodingResult
导入
HelloServiceProxy.java
,如下所示:

我使用
mvn clean install-PautoInstallPackage

但是,当我尝试将组件添加到页面时,出现以下错误:

错误:未解决的编译问题:只能使用类型 进口的。com.google.maps.model.GeocodingResult解析为一个包

以下是错误的屏幕截图:

更新1

我从另一个全新的AEM项目开始,做了以下几件事:

  • 在core/pom.xml中为
    maven bundle插件添加了如下配置设置

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

    该错误表示
    google地图服务
    捆绑包中的类对
    hometest.core
    捆绑包不可用。这很可能是因为嵌入bundle在这一点上不起作用


    您能否尝试部署一个单独的包,其中嵌入
    谷歌地图服务
    ,看看是否有效?

    我尝试了另一个包,并更新了我在问题中所做的工作。错误与以前相同..能否打开hometest捆绑包的jar内容,查看其manifest.mf的“导入包”标题中是否列出了google maps服务包。如果它有一个正确的版本,那么请检查谷歌捆绑包的导出包部分是否存在相同的包。如果这不起作用,请尝试使用maven bundle插件的属性,而不是使用。@Anthony您能清除jsp编译错误吗?抱歉,我错过了更新。我的意思是使用mvn sling:install或Felix Web控制台部署另一个捆绑包,然后重试。我以前见过这个问题。有时,强迫重新编译视图或ui的表面更改会有所帮助。我对它不是很了解。但可能是core和ui包中的依赖关系试图使用一个在ui jsp启动时未注册的服务compiled@ChristopherRockwell您是如何解决的?您可能对我最近发布的一个问题感兴趣,但我没有导出罐子,只是嵌入了。因此,它们只能在服务/核心捆绑包中使用。。。。此外,关于“只能导入一个类型”的问题,我之前已经通过重新部署视图“解决”了这个问题,在另一种情况下,我只是在JSP中保存一个空格更改(强制重新编译)。但是如果是我,我会嵌入(而不是导出)罐子,如果可能的话,在同一个包中使用它们,即使你不是真正的osgi方式,你能解决这个问题吗?
    <dependency>
    <groupId>com.google.maps</groupId>
    <artifactId>google-maps-services</artifactId>
    <version>0.1.7</version>
    <scope>compile</scope>
    </dependency>
    
    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