如何从OSGi组件中的第三方jar文件导入类 [英] How to import a class from third party jar file in an OSGi component
问题描述
我正在使用 https://eclipse.adobe.com/aem/dev-tools /创建一个项目.创建后,我在Eclipse中具有以下结构:
I am using https://eclipse.adobe.com/aem/dev-tools/ to create a project. Once created, I have the following structure in eclipse:
我希望能够在我的组件中使用GoogleMaps API.所以我在hometest.core/pom.xml
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>
我还已将所有内容添加到hometest.core/pom.xml
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>
然后我将com.google.maps.model.GeocodingResult
导入到HelloServiceProxy.java
中,如下所示:
I then import com.google.maps.model.GeocodingResult
into HelloServiceProxy.java
as shown below:
我使用mvn clean install -PautoInstallPackage
但是,当我尝试将组件添加到页面时,出现以下错误:
However, when I try to add the component to the page I get the following error:
java.lang.Error:未解决的编译问题:只能是一个类型 进口的. com.google.maps.model.GeocodingResult解析为包
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:
更新1
我从另一个全新的AEM项目开始,做了以下事情:
I started with another brand new AEM project and did the following things:
-
在core/pom.xml中为
maven-bundle-plugin
添加了这样的配置设置
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>
像这样添加了google maps依赖项:
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>
部署了此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
推荐答案
该错误表明google-maps-services
捆绑包中的类不适用于hometest.core
捆绑包.很有可能嵌入包此时无法正常工作.
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.
您可以尝试部署嵌入google-maps-services
的单独捆绑软件,看看是否可行吗?
Can you try deploying a separate bundle which embeds google-maps-services
and see if that works?
这篇关于如何从OSGi组件中的第三方jar文件导入类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!