Expand my Community achievements bar.

SOLVED

Issue with SCR annotations in CRXde lite

Avatar

Level 4

Hi,

I am trying to compile and build the below servlet in CRXde lite and it is not getting built (though it is not recommended)

package foo.bar;

import java.io.IOException;

import javax.servlet.ServletException;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;


@Component()
@Service()

@SlingServlet(paths="/bin/userlist", metatype = false)
public class UserServlet extends SlingAllMethodsServlet {

    private static final long serialVersionUID = -9067150309356760626L;
    //private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Reference
    private ResourceResolverFactory resolverFactory;
    
    @Override
    protected void doGet(SlingHttpServletRequest request,
            SlingHttpServletResponse response) throws ServletException,
            IOException {

        userListJSON(request, response);
        
    }

    @Override
    protected void doPost(SlingHttpServletRequest request,
            SlingHttpServletResponse response) throws ServletException,
            IOException {
        userListJSON(request, response);

    }

    protected void userListJSON(SlingHttpServletRequest request,
            SlingHttpServletResponse response){

        response.setContentType("application/json");

        } 
    }

 

It is throwing the below 2 errors. Could anyone please help in resolving this. Please note that I am not able to create this using Eclipse and maven due to some proxy issues at the moment. 

1. Class has more than one component definition. Check the annotations and merge the definitions to a single definition.

2. SCR Descriptor parsing had failures (see log)

 

1 Accepted Solution

Avatar

Correct answer by
Level 10

CRXDE lite is not a good way to build OSGi bundles (either services or servlets). Your code looks fine and should work. Take a look at this old article that talks about using CRXDE lite to build OSGi:

https://helpx.adobe.com/experience-manager/using/creating-osgi-bundles-digital-marketing.html

Also notice the note in this article: 

Update: It is recommended that you no longer use CRXDE to create OSGi bundles for AEM. Instead use Maven. For information, see Creating your first AEM Service using an Adobe Maven Archetype project.

As soon as you can - i recommend moving over to Maven ASAP. 

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

CRXDE lite is not a good way to build OSGi bundles (either services or servlets). Your code looks fine and should work. Take a look at this old article that talks about using CRXDE lite to build OSGi:

https://helpx.adobe.com/experience-manager/using/creating-osgi-bundles-digital-marketing.html

Also notice the note in this article: 

Update: It is recommended that you no longer use CRXDE to create OSGi bundles for AEM. Instead use Maven. For information, see Creating your first AEM Service using an Adobe Maven Archetype project.

As soon as you can - i recommend moving over to Maven ASAP. 

Avatar

Level 4
Thanks Scott for the update. I used to work only with maven. However i was facing some weird issues with my maven build due to proxy or network related. While doing clean install on new multimodule project, maven is downloading only 3kb jar files which are all corrupt files... Please note that I am using a company desktop machine where I doesn't have an option to connect to an open network to download the dependencies... That's how I ended up using a CRX de lite as a quick work around but without any luck :-(

Avatar

Employee

Have you tried using code in an example article(see below), any reason you are declaring the servlet as a service and a component? Just take the class below and have a very simple doGet method.

https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/java/com/ad...

https://helpx.adobe.com/experience-manager/using/sling_servlet_mbean.html