我正在尝试为路径浏览器实现自定义 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/