You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OSGi环境下AEM项目google-maps-services包装Bundle依赖嵌入失败问题排查

Troubleshooting Google Maps Services OSGi Bundle Startup in AEM

Alright, let's break down what's going wrong with your OSGi bundle setup for Google Maps Services in AEM, and fix it step by step. The core issues here are conflicting BND configurations, incorrect handling of import/embed rules, and unnecessary forced dependencies.

Key Problems in Your Current Setup

  1. Overridden Import Packages: You explicitly set Import-Package: javax.annotation;version=0.0.0 which overrides BND's automatic dependency calculation. This means all other required packages (like okhttp3, okio, etc.) aren't being imported, causing the bundle to fail resolving dependencies.
  2. Conflict Between Export Rules: You're using both Export-Package and -exportcontents, which can lead to unexpected package exports or conflicts.
  3. Unnecessary Embedding: Some dependencies (like okhttp/okio) might already be provided by AEM's core bundles, so embedding them creates redundancy or version conflicts.
  4. Forced Optional Dependency: The appengine-api is an optional dependency for Google Maps Services (only needed for Google App Engine environments), but your current setup treats it as a required import.

Step-by-Step Fixes

1. Correct the Import-Package Configuration

First, fix the import rules to let BND automatically handle most dependencies while explicitly defining critical ones (with version ranges) and marking optional dependencies as such:

Import-Package: javax.annotation;version="[0.0.0,2.0.0)", com.google.appengine.api;resolution:=optional, *
  • The * tells BND to auto-import all other required packages.
  • resolution:=optional makes the App Engine dependency non-mandatory, so the bundle can start without it in AEM.

2. Refine Embed-Dependency to Only Include Necessities

Only embed dependencies that aren't already provided by AEM. For AEM 6.5+, okhttp and okio are typically available via core bundles, so we can skip embedding them. We'll keep embedding google-maps-services and opencensus-api (since AEM doesn't provide this by default):

Embed-Dependency: google-maps-services,opencensus-api;inline=true
  • inline=true ensures the embedded JARs' classes are merged directly into your bundle, avoiding issues with nested JARs in OSGi.

3. Clean Up Export-Package Configuration

Remove the conflicting -exportcontents rule and explicitly define your exports with a version (following OSGi best practices):

Export-Package: com.google.maps.*;version="0.18.0"

This ensures only the Google Maps Services packages are exported, not any embedded dependency packages.

4. Full Corrected BND Configuration

Putting it all together, your BND config should look like this:

Bundle-Category: thirdparty
Import-Package: javax.annotation;version="[0.0.0,2.0.0)", com.google.appengine.api;resolution:=optional, *
Export-Package: com.google.maps.*;version="0.18.0"
Embed-Dependency: google-maps-services,opencensus-api;inline=true
-snapshot: ${tstamp;yyyyMMddHHmmssSSS}

5. Update Maven Dependencies

Mark optional dependencies as such in your POM to avoid unnecessary transitive dependencies:

<dependency>
  <groupId>com.google.appengine</groupId>
  <artifactId>appengine-api-1.0-sdk</artifactId>
  <version>1.9.88</version>
  <optional>true</optional>
</dependency>
<dependency>
  <groupId>com.squareup.okhttp3</groupId>
  <artifactId>okhttp</artifactId>
  <version>3.14.4</version>
  <optional>true</optional>
</dependency>
<dependency>
  <groupId>com.squareup.okio</groupId>
  <artifactId>okio</artifactId>
  <version>1.17.2</version>
  <optional>true</optional>
</dependency>

Final Checks

After rebuilding and deploying the bundle:

  • Check the OSGi console (/system/console/bundles) to verify the bundle is active.
  • If any dependencies are still missing, check if AEM provides them (use the OSGi console's "Packages" tab to search) or adjust the Embed-Dependency list accordingly.

内容的提问来源于stack exchange,提问作者Thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 12:52:45