Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Basic : Development environment set up

Avatar

Level 9

Hi All,

I am trying out basic code examples in 5.6.1 AEM instance.

For example, I was trying the article "http://helpx.adobe.com/experience-manager/using/programmatically-accessing-cq-content-using.html" and it requires eclipse, jackrabbit standalone jar and it works fine.

However, if I have to try some other basic code examples, I am not at all getting how do I do it.

I have local maven repository,eclipse. 

I could follow as it is the article http://helpx.adobe.com/experience-manager/using/creating-custom-aem-workflow-steps.html.

1] But in case I have to write my own code[say some custom workflow code], should I follow the same steps as mentioned in http://helpx.adobe.com/experience-manager/using/creating-custom-aem-workflow-steps.html[excepting that replace the java code with mine].

2] The reason I am having problem is if I make use of the above step, in eclipse it doesn''t give me the intelli-sense option and also it throws error against every line[irrespective of the code being correct or not].

3] Can some one please provide me the detailed/exact steps how to go about setting up the development environment.

1 Accepted Solution

Avatar

Correct answer by
Level 10

When writing your own Service (and your own Java logic) - you have to get all of the dependences into the Maven POM file. For example - lets assume that you use Google GSON Java API in your code. 

https://code.google.com/p/google-gson/

Then you will have to get this dependency into your Maven POM file:

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.2.4</version>
</dependency>

Use the Maven POM that is displayed in Eclipse after you import the Project into Eclipse. 

[img]POM.png[/img]

Also - when using a Java API - in addition to making sure that the API is referenced in the POM file, you have to make sure that the JAR is always in CQ as a Bundle fragment. For this use case -- lets look at this development article:

http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

This development article uses org.json.simple.JSONObject. Therefore -- we need this dependency in the Maven POM file:

<dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>

And we have to place this JAR file into CQ as an OSGi bundle fragment - as discussed in the previous article. 

Therefore - keep these 2 rules in mind when writing a custom service and using 3rd party Java APIs:

1 - make sure that you reference the dependency into the POM file

2 - make sure that the JAR file is deployed to CQ within an OSGi bundle fragment. 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

When writing your own Service (and your own Java logic) - you have to get all of the dependences into the Maven POM file. For example - lets assume that you use Google GSON Java API in your code. 

https://code.google.com/p/google-gson/

Then you will have to get this dependency into your Maven POM file:

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.2.4</version>
</dependency>

Use the Maven POM that is displayed in Eclipse after you import the Project into Eclipse. 

[img]POM.png[/img]

Also - when using a Java API - in addition to making sure that the API is referenced in the POM file, you have to make sure that the JAR is always in CQ as a Bundle fragment. For this use case -- lets look at this development article:

http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

This development article uses org.json.simple.JSONObject. Therefore -- we need this dependency in the Maven POM file:

<dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>

And we have to place this JAR file into CQ as an OSGi bundle fragment - as discussed in the previous article. 

Therefore - keep these 2 rules in mind when writing a custom service and using 3rd party Java APIs:

1 - make sure that you reference the dependency into the POM file

2 - make sure that the JAR file is deployed to CQ within an OSGi bundle fragment. 

Avatar

Level 10

Another follow-up -- in the development articles -- we use Maven to build the AEM OSGi bundles - not Eclipse.  All OSGi bundles are compiled and built from the command line using:

mvn clean install

If there are errors - Maven will tell you what is wrong -- not Eclipse

If you want to compile and build your OSGi project via Eclipse (and use intelli-sense in eclipse) - then you can use the Maven eclipse plug-in. See:

http://maven.apache.org/eclipse-plugin.html