[英]How to import a class from third party jar file in an OSGi component
我使用https://eclipse.adobe.com/aem/dev-tools/来创建一个项目。 一旦创建,我在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>
我还在hometest.core/pom.xml
的_exportcontents
中添加了所有内容
<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
将包安装到aem的本地实例
但是,当我尝试将组件添加到页面时,我收到以下错误:
java.lang.Error:未解决的编译问题:只能导入一个类型。 com.google.maps.model.GeocodingResult解析为一个包
以下是错误的屏幕截图:
更新1
我从另一个全新的AEM项目开始,做了以下事情:
在core / pom.xml中添加了maven-bundle-plugin
配置设置
<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>
像这样添加谷歌地图依赖:
<dependency> <groupId>com.google.maps</groupId> <artifactId>google-maps-services</artifactId> <version>0.1.7</version> <scope>compile</scope> </dependency>
使用此mvn clean install -PautoInstallPackage
部署
当我尝试向页面添加组件时,我收到错误:
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
该错误表示google-maps-services
包中的类不可用于hometest.core
包。 很可能嵌入束在这一点上不起作用。
您是否可以尝试部署一个嵌入google-maps-services
的单独捆绑包,看看它是否有效?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.