我正在尝试为pathbrowser实现自定义的OSGI服务谓词。如果有人知道这段代码出了什么问题:)下面有个例外。可能是@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
发布于 2017-01-26 17:05:49
当您从AEM扩展一个带有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很有趣,尽管它属于测试版。
发布于 2017-01-26 20:08:37
只要尝试实现org.apache.commons.collections.Predicate
即可。
另外:resource.getResourceType().equals("cq:Page")
永远不会是true
,因为cq:Page
是资源的jcr:pimaryType
。page.getTemplate()
在发布时不起作用:
public booean evaluate(Resource resource) {
if (null == resource) return false;
final ValueMap map = resource.getValueMap();
return "cq:Page".equals(map.get("jcr:primaryType", "")
&& CQ_TEMPLATE_CONTENT.equals(map.get("cq:template", "")
}
https://stackoverflow.com/questions/41868527
复制相似问题