java - 在 AEM 6.2 中创建自定义路径浏览器谓词

标签 java maven osgi aem

我正在尝试为路径浏览器实现自定义 OSGI 服务谓词。如果有人知道这段代码有什么问题:) 下面有异常(exception)。也许是 @Component 或依赖项的问题

<path jcr:primaryType="nt:unstructured"
      sling:resourceType="granite/ui/components/foundation/form/pathbrowser"
      fieldDescription="List item link" 
      fieldLabel="List Item link"
      name="./path"
      predicate="predicate"
      rootPath="/content">
</path>

谓词实现:

import org.apache.commons.collections.Predicate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;

import com.day.cq.commons.predicate.AbstractResourcePredicate;
import com.day.cq.wcm.api.Page;

@Component(label = "Content-page Predicate", description = "This predicate is used to restricted to allow selection of pages that have template content-page")
@Service(value = Predicate.class)
@Properties({
     @Property(label = "Predicate Name", name = "predicate.name", value = "predicate", propertyPrivate = true) })
public class ContentPagePredicate extends AbstractResourcePredicate {

    private static final String CQ_TEMPLATE_CONTENT = "/conf/xxx-lab/settings/wcm/templates/content-page";

    @Override
    public boolean evaluate(Resource resource) {
        if (null != resource) {
            if (!resource.getResourceType().equals("cq:Page")) {
                return false;
            }
            Page page = resource.adaptTo(Page.class);

            return page.getTemplate().getName().equals(CQ_TEMPLATE_CONTENT);

        }
        return false;
    }
}

Maven 构建输出:

[ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.20.0:scr (generate-scr-scrdescriptor) on project SomethingDemo.core: Execution generate-scr-scrdescriptor of goal org.apache.felix:maven-scr-plugin:1.20.0:scr failed: An API incompatibility was encountered while executing org.apache.felix:maven-scr-plugin:1.20.0:scr: java.lang.VerifyError: Constructor must call super() or this() before return
[ERROR] Exception Details:
[ERROR] Location:
[ERROR] com/day/cq/commons/predicate/AbstractNodePredicate.<init>()V @1: return
[ERROR] Reason:
[ERROR] Error exists in the bytecode
[ERROR] Bytecode:
[ERROR] 0x0000000: 2ab1 

最佳答案

当您从 AEM API 扩展一个带有 SCR 注释(用于生成 OSGi 包描述符)的类时,可能会发生您看到的错误,同时在您使用的 Uber Jar 中进行混淆。

您可以在Adobe's public Maven repository中找到您正在使用的AEM版本的未混淆的Uber Jar。 .

如果您代表客户或合作伙伴,您还应该能够从帮助网站 https://daycare.day.com/home/products/uberjar.html 下载一个。

如果您的项目使用的存储库已经包含未混淆的 Jar,那么它应该像更改依赖项一样简单。

例如,在使用带有混淆类的 AEM 6.2 Uber Jar 的项目中

<dependency>
    <groupId>com.adobe.aem</groupId>
    <artifactId>uber-jar</artifactId>
    <version>6.2.0</version>
    <scope>provided</scope>
    <classifier>obfuscated-apis</classifier>
</dependency>

只需更改分类器即可获得未混淆的版本:

<dependency>
    <groupId>com.adobe.aem</groupId>
    <artifactId>uber-jar</artifactId>
    <version>6.2.0</version>
    <scope>provided</scope>
    <classifier>apis</classifier>
</dependency>

看看这个 Github issue对非常相似的问题进行更广泛的讨论。

您可能还会发现这个Adobe Help Forum thread有趣的, 尽管它属于测试版。

关于java - 在 AEM 6.2 中创建自定义路径浏览器谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41868527/

相关文章:

Maven-ear-plugin 未复制 xml 文件

java - 使用 Eclipse 声明编译和运行时之间的暂时依赖关系的最佳方法是什么?

Maven:制作具有依赖关系的 jar :书中的例子不起作用

java - 将现有 Maven 项目迁移到 OSGI Bundle

java - 我可以将 osgi.enterprise.jar 放在我的 Equinox 插件文件夹中吗?

java - 使用indexOf读入文本文件行以分隔数组

java - 安装应用程序时出现 "Picked up _java_options"消息,但未设置环境变量

java - 关于 java : get `String[].class` from `String.class` , 如果 `String.class` 是 "runtime type"怎么办?

java - 在 Struts 1.x JSP 中填充多个表单

java - 如何使用 Eclipse P2 处理 Java 提供的包