best-practices
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAEM as a Cloud Service — Best Practices
AEM as a Cloud Service — 最佳实践
Platform guidance for AEM as a Cloud Service: Java/OSGi (what to use, what to avoid, how to refactor legacy patterns) and HTL (component templates, Cloud SDK HTL lint).
.htmlThis skill holds the pattern transformation modules (). They ship with the plugin; use this skill without the migration skill for greenfield or maintenance work that only needs these references. Use migration when you need BPA/CAM orchestration on top.
references/*.mdaem-cloud-serviceQuick pick: Open the Pattern Reference Modules table below → jump to the matching → read it fully before editing. For Java: Felix SCR, resolvers, or logging, use Java / OSGi baseline links first when those appear in the same change set.
references/<file>.mdAEM as a Cloud Service平台指南:Java/OSGi(适用方案、规避事项、遗留模式重构方法)以及HTL(组件模板、Cloud SDK HTL代码检查)。
.html本技能包含模式转换模块(),随**插件一同发布;若仅需这些参考模块进行新项目开发或维护工作,可单独使用本技能,无需搭配迁移技能。如需BPA/CAM编排功能,则需使用迁移**技能。
references/*.mdaem-cloud-service快速指引: 打开下方的「模式参考模块」表格 → 跳转至对应的文件 → 在编辑代码前完整阅读该模块内容。针对Java相关的Felix SCR、解析器或日志问题,当同一变更集中出现相关链接时,请优先查看Java / OSGi基线链接。
references/<file>.mdWhen to Use This Skill
适用场景
Use this skill when you need to:
- Apply AEM as a Cloud Service constraints to Java/OSGi code (new or existing)
- Refactor legacy Java patterns into supported APIs (same modules migration uses)
- Follow consistent rules across schedulers, replication, JCR observation listeners (), OSGi event handlers (
eventListener), and DAM assetseventHandler - Fix HTL (Sightly) issues from the AEM Cloud SDK build, especially
data-sly-test: redundant constant value comparison - Read step-by-step transformation and validation checklists for a specific pattern
For BPA/CAM orchestration (collections, CSV, MCP project selection), use the skill ().
migrationskills/aem/cloud-service/skills/migration/在以下场景中可使用本技能:
- 为Java/OSGi代码(新代码或现有代码)应用AEM as a Cloud Service约束
- 将遗留Java模式重构为受支持的API(与迁移技能使用相同模块)
- 在调度器、复制机制、JCR监听监听器()、OSGi事件处理器(
eventListener)和DAM资源方面遵循统一规则eventHandler - 修复AEM Cloud SDK构建中出现的**HTL (Sightly)**问题,尤其是警告
data-sly-test: redundant constant value comparison - 阅读特定模式的分步转换和验证检查清单
如需BPA/CAM编排(集合、CSV、MCP项目选择),请使用****技能()。
migrationskills/aem/cloud-service/skills/migration/Pattern Reference Modules
模式参考模块
Each supported pattern has a dedicated module under relative to this .
references/SKILL.md| Pattern / topic | BPA Pattern ID | Module file | Status |
|---|---|---|---|
| Scheduler | | | Ready |
| Resource Change Listener | | | Ready |
| Replication | | | Ready |
| Event listener (JCR observation) | | | Ready |
| Event handler (OSGi Event Admin) | | | Ready |
| Asset Manager | | | Ready |
| Felix SCR → OSGi DS | — | | Ready |
| ResourceResolver + SLF4J | — | | Ready |
HTL: | — (HTL lint) | | Ready |
| (Prerequisites hub) | — | | — |
Event listener vs event handler (not the same): is JCR observation — the JCR API for repository change callbacks (, ). is OSGi Event Admin — whiteboard-style OSGi events (, ). Both migrate via (Path A vs Path B). is separate: Sling , module .
eventListenerjavax.jcr.observation.EventListeneronEventeventHandlerorg.osgi.service.event.EventHandlerhandleEventreferences/event-migration.mdresourceChangeListenerResourceChangeListenerreferences/resource-change-listener.mdBefore changing code for a pattern: read the module for that pattern in full. Modules include classification criteria, ordered transformation steps, and validation checklists.
每个受支持的模式在本相对路径下的目录中都有对应的专属模块。
SKILL.mdreferences/| 模式/主题 | BPA模式ID | 模块文件 | 状态 |
|---|---|---|---|
| Scheduler | | | 已就绪 |
| Resource Change Listener | | | 已就绪 |
| Replication | | | 已就绪 |
| Event listener (JCR observation) | | | 已就绪 |
| Event handler (OSGi Event Admin) | | | 已就绪 |
| Asset Manager | | | 已就绪 |
| Felix SCR → OSGi DS | — | | 已就绪 |
| ResourceResolver + SLF4J | — | | 已就绪 |
HTL: | — (HTL lint) | | 已就绪 |
| (前置条件中心) | — | | — |
Event listener与event handler的区别: 是JCR监听——用于仓库变更回调的JCR API(、)。是OSGi Event Admin——白板风格的OSGi事件(、)。两者均通过**进行迁移(路径A vs 路径B)。是独立模块:Sling ,对应模块为**。
eventListenerjavax.jcr.observation.EventListeneronEventeventHandlerorg.osgi.service.event.EventHandlerhandleEventreferences/event-migration.mdresourceChangeListenerResourceChangeListenerreferences/resource-change-listener.md在针对某一模式修改代码前: 完整阅读该模式对应的模块内容。模块包含分类标准、有序的转换步骤和验证检查清单。
Java / OSGi baseline (same skill; no separate installables)
Java / OSGi基线(同属本技能;无需单独安装)
SCR→DS and /logging are reference modules under — not separate skills. Read them when relevant instead of re-embedding the same steps inside each pattern file.
ResourceResolverreferences/- Hub:
references/aem-cloud-service-pattern-prerequisites.md - Modules: ,
references/scr-to-osgi-ds.mdreferences/resource-resolver-logging.md
SCR→DS和/日志相关内容是目录下的参考模块——并非独立技能。当涉及相关内容时,请阅读这些模块,而非在每个模式文件中重复嵌入相同步骤。
ResourceResolverreferences/- 中心入口:
references/aem-cloud-service-pattern-prerequisites.md - 模块: 、
references/scr-to-osgi-ds.mdreferences/resource-resolver-logging.md
Critical Rules (All Patterns)
核心规则(所有模式通用)
These rules apply to every pattern module. Violation means incorrect migration or unsafe Cloud Service code.
- READ THE PATTERN MODULE FIRST — never transform code without reading the module
- READ and
scr-to-osgi-ds.mdwhen SCR,resource-resolver-logging.md, or logging are in scope (pattern modules link via the prerequisites hub; do not duplicate long guides inline)ResourceResolver - DO preserve environment-specific guards (e.g. run mode checks)
isAuthor() - DO NOT change business logic inside methods (Java) or logical show/hide intent (HTL) unless the module explicitly allows it
- DO NOT rename classes unless the pattern module explicitly says to
- DO NOT invent values — extract from existing code
- DO NOT edit files outside the scope agreed with the user (e.g. only BPA targets or paths they named)
- DO keep searches, discovery, and edits for the customer's AEM sources inside the IDE workspace root(s) currently open; DO NOT grep or walk directories outside that boundary to find Java unless the user explicitly points there
以下规则适用于所有模式模块。违反规则意味着迁移错误或云服务代码存在安全风险。
- 务必先阅读模式模块——绝不跳过阅读模块直接转换代码
- 当涉及SCR、或日志内容时,务必阅读
ResourceResolver和scr-to-osgi-ds.md(模式模块会通过前置条件中心链接至这些内容;请勿在模块内重复冗长指南)resource-resolver-logging.md - 务必保留环境特定的防护逻辑(例如运行模式检查)
isAuthor() - 请勿修改方法内的业务逻辑(Java)或逻辑显示/隐藏意图(HTL),除非模块明确允许
- 请勿重命名类,除非模式模块明确要求
- 请勿自行编造值——从现有代码中提取
- 请勿修改与用户约定范围外的文件(例如仅修改BPA目标或用户指定路径下的文件)
- 务必在当前打开的IDE工作区根目录内搜索、发现和编辑客户的AEM源代码;请勿在该边界外遍历目录查找Java文件,除非用户明确指定
Manual Pattern Hints (Classification)
手动模式识别提示(分类)
When no BPA list exists, scan imports and types to pick a module:
| Look for | Pattern |
|---|---|
| |
| |
| |
JCR observation: | |
OSGi Event Admin: | |
| |
| read |
| read |
HTL: build warning | read |
If multiple patterns match, ask which to fix first.
当无BPA列表时,可通过扫描导入语句和类型选择对应模块:
| 查找关键词 | 对应模式 |
|---|---|
| |
| |
| |
JCR监听: | |
OSGi Event Admin: | |
| |
| 阅读 |
| 阅读 |
HTL: 构建警告 | 阅读 |
若多个模式匹配,请询问用户优先修复哪一个。
Relationship to Migration
与迁移技能的关系
The skill defines one-pattern-per-session workflow, BPA/CAM/MCP flows, and user messaging. It delegates all detailed transformation steps to this skill's modules. It uses a repo-root path alias to this folder (see its ). Keep platform truth here; keep orchestration there.
migrationreferences/{best-practices}SKILL.mdmigrationreferences/{best-practices}SKILL.md