Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Only a type can be imported. org.apache.felix.scr.annotations.Component resolves to a package

Avatar

Employee

I copied the example code exactly, but it won't compile. I receive errors on all the annotations, like:

"Only a type can be imported. org.apache.felix.scr.annotations.Component resolves to a package"

and

"Component cannot be resolved to a type"

 

---------------------------------------------------------------------- ---

package com.day.cq.wcm.apps.geometrixx.impl;

 

import com.day.cq.workflow.WorkflowException;

import com.day.cq.workflow.WorkflowSession;

import com.day.cq.workflow.exec.WorkItem;

import com.day.cq.workflow.exec.WorkflowData;

import com.day.cq.workflow.exec.WorkflowProcess;

import com.day.cq.workflow.metadata.MetaDataMap;

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.osgi.framework.Constants;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

 

import javax.jcr.Node;

import javax.jcr.RepositoryException;

 

/**

* Sample workflow process

*/

@Component

@Service

@Properties({

@Property(name = Constants.SERVICE_DESCRIPTION, value = "A sample workflow process implementation."),

@Property(name = "process.label", value = "Sample Workflow Process")})

 

public class CustomWorkflow implements WorkflowProcess {

 

private static final String TYPE_JCR_PATH = "JCR_PATH";

private static final Logger log = LoggerFactory.getLogger(CustomWorkflow.class);

 

public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException {

WorkflowData workflowData = item.getWorkflowData();

if (workflowData.getPayloadType().equals(TYPE_JCR_PATH)) {

String path = workflowData.getPayload().toString();

// More code here

}

}

 

}

 

Errors :

 

                               
DescriptionResourcePath 
Component cannot be resolved to a type.java/li
Only a type can be imported. org.apache.felix.scr.annotations.Component resolves to a package.java/li
Properties cannot be resolved to a type.java/l 
Service cannot be resolved to a type.java  
1 Accepted Solution

Avatar

Correct answer by
Employee

try to build the bundle (instead of compiling).
Reason being the annotations are processed at build time (by the scr maven plugin) and an xml service descriptor is generated which is inside the final bundle. The classes are not even visible at run time. The scr annotations are only processed when building the bundle: right-click on the .bnd file -> "Build Bundle"

View solution in original post

2 Replies

Avatar

Correct answer by
Employee

try to build the bundle (instead of compiling).
Reason being the annotations are processed at build time (by the scr maven plugin) and an xml service descriptor is generated which is inside the final bundle. The classes are not even visible at run time. The scr annotations are only processed when building the bundle: right-click on the .bnd file -> "Build Bundle"

Avatar

Employee

You might be importing the wrong ComponentContext if you're using one in your activate method's signature.  CRXDE gives errors with no explanation in that case.  Ensure that you have:

 

import org.osgi.service.component.ComponentContext;

 

as there are a couple of other ComponentContext classes and the class from the osgi package may not be the default chosen by CRXDE when imports are auto-populated.