AEM Developer Tools for Eclipse
Tags: aem
Published: 2019-09-16 01:27:50

This page contains tips and resources for using Eclipse with Adobe Experience Manager (AEM). The first tip covers how to setup a simple Sling Content project and use it to transfer files between the local file system and AEM's Java Content Repository (JCR).

### Requirements

*   Download and install Eclipse IDE for Java EE Developers (Eclipse Kepler or newer), [eclipse.org/downloads/packages/release](https://www.eclipse.org/downloads/packages/release)

*   Install [AEM Developer Tools](https://eclipse.adobe.com/aem/dev-tools/) For more information, [helpx.adobe.com/experience-manager/6-4/sites/developing/using/aem-eclipse.html](https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/aem-eclipse.html)

### Setup

<ol>
  <li>
    <p>
      <b>AEM Perspective</b><br />
      From the menu, select Window > Perspective > Open Perspective > AEM
    </p>
  </li>
  <li>
    <p>
      <b>Create New Sling Content Project</b><br />
      From the menu, select File > New > Project > Sling > Sling Content Project
      <figure style="max-width:600px">
        <img src="https://thepracticaldev.s3.amazonaws.com/i/rxvxmivihvbxmk3n94ej.png"
          alt="Create New Sling Content Project"
        />
        <figcaption>
          check "Show All Wizards" if needed
        </figcaption>
      </figure>
    </p>
  </li>
  <li>
    <p>
      Select or Create the AEM Server when prompted, or right click in the
      Servers panel and select New > Server > Adobe Experience Manager. The
      defaults should work fine for a localhost AEM server instance using the
      default admin account credentials.
    </p>
    <blockquote>
      If your AEM instance is running in a
      <a href="https://jimfrenette.com/2019/01/aem-dispatcher-centos-virtual-machine-setup/"
        >Virtual Machine (VM)</a
      >, you may want to update your hosts file to map a hostname to the
      machines IP address. For example, <code>192.168.122.111 aem-box</code>
    </blockquote>
  </li>
  <li id="resources">
    <p>
      <b>Resources</b><br />
      If you did not add a server during the project creation wizard, or need to
      add a project resource.<br />
      In the Servers panel,<br />
      Right-click on the server,<br />
      Select Add and Remove,<br />
      Drag the available resource to the configured column,<br />
      e.g., add <code>myproject</code>
    </p>
  </li>

  <li>
    <p>
      <b>AEM Console</b><br />
      From the Open Console menu (red circle in image below), select AEM Console
      to monitor the server startup synchronization and subsequent file
      transfers.<br />
      In the Servers panel, right click on the server to start or stop as
      needed.
    </p>

    <p>
      <img src="https://thepracticaldev.s3.amazonaws.com/i/ztwnpievp8pbqxq6xmxh.png" /><br />
      <small>AEM Eclipse Perspective and Open Console Menu</small>
    </p>
  </li>
</ol>

### Navigator

By default, the Project Workspace tab neglects to show `.content.xml` files imported from the JCR. This can be changed using the Menu dropdown within the panel. Select Filters and Customization to open the dialog to configure what files to show.

I prefer to add the Navigator panel to the perspective and use it instead since it will show all of my files and folders without any modifications.

<figure style="max-width:400px">
  <img 
    src="https://thepracticaldev.s3.amazonaws.com/i/5x6kd0igcetsypihd497.png"
    alt="Eclipse Menu - Window > Show > View > Navigator"
  />
  <figcaption>
    Adding Navigator to the Perspective
  </figcaption>
</figure>

### Transfer Files

To transfer files and folders to the AEM Server, right-click the file or folder and select Export to server. This can be done in either the Navigator or Project panels. The Sling Repository Export dialog will prompt you for the Repository to export content to. Typically this will match the name of the configured AEM server.

To transfer files and folders from the AEM Server, right-click the file or folder and select Import from server.

>   If you receive this error when you attempt to import/export \
**No valid filter found in this project!** \
Delete the project from workspace using the Project Explorer in Eclipse. Then re-create it using the wizard. Ignore the message that a `jcr_root` already exists if your [project is linked](#project-linking), it is a symlink.

To automatically transfer saved file changes to the server, check the Server Publishing settings. Options are:

*   Never publish automatically
*   Automatically publish when resources change
*   Automatically publish after build event

#### Importing

**Folders and Files Created with CRXDE Lite**

For folders, files and nodes that have been created within CRXDE Lite and do not yet have a respective Sling Content poject in Eclipse. Here are some tips on how to import these from the JCR. 

1.  Create New Sling Content Project as described under Setup > Step 2 above.

2.  Edit the `filter.xml` file in `META-INF/vault` to include the JCR repository folder paths as needed. e.g.,</p>

```
<workspaceFilter vesion="1.0">
  <filter root="/apps/myproject"/>
  <filter root="/content/my-project"/>
</workspaceFilter>
```

3.  In the New Sling Content Project `jcr_root` folder, rename the `example` folders under `apps` and `content` with the names used in your CRXDE Lite project as needed.

4.  You should now be able to right-click on the folders and select Sling > Import from server...

### Project Linking

You may have an existing AEM repo and/or project folder that you prefer not to move into the eclipse workspace. These steps will show you how to link them to the new Sling Content Project created above.

>   When creating your project using the wizard, consider giving it the same name as the existing AEM project folder you are linking. If you rename the project created by the wizard, you may need to re-attach it to the server. Right-click in the Servers panel and select Add and Remove.

1.  To link an existing AEM project which should already have its own `jcr_root` and `META-INF` folders. Remove the `jcr_root` and `META-INF` folders created by the wizard if they already exist in the source project. For example,

```
cd ~/eclipse-workspace/myproject
rm -rf jcr_root
rm -rf META-INF
```

2.  Symlink the new `eclipse-workspace` project to the existing AEM project `jcr_root`. For example, if your existing project `jcr_root` is in `/home/dinesh/dev/aem/myproject/src/main/content/jcr_root`

```
cd ~/eclipse-workspace/myproject

ln -sv /home/dinesh/dev/aem/myproject/src/main/content/jcr_root jcr_root
```

3.  Repeat for `META-INF`

```
ln -sv /home/dinesh/dev/aem/myproject/src/main/content/META-INF META-INF
```

### Components

This example shows how to create components.

In the Project panel, expand the `myproject` > `jcr_root[nt:folder]`.

Right click on the `/apps/example` folder and select New > node. 

<figure style="max-width:800px">
  <img 
    src="https://thepracticaldev.s3.amazonaws.com/i/bq8dt9jb6bgegkamsnic.png"
    alt="Eclipse AEM Project example - New > node"
  />
  <figcaption>
    New node menu
  </figcaption>
</figure>

**name**: `components`

<figure style="max-width:500px">
  <img 
    src="https://thepracticaldev.s3.amazonaws.com/i/bbk6ktljhwwqrfy0ds3o.png"
    alt="Eclipse AEM Project example - Enter Node Name dialog for nt:folder node"
  />
  <figcaption>
    New nt:folder node
  </figcaption>
</figure>

>   If you get this error: Unable to validate node types since project myproject is not associated with a server or the server is not started. Start the server and/or verify the project is a configured [resource](#resources).

Right-click on the new `components` folder and select New  > node.

<figure style="max-width:500px">
  <img 
    src="https://thepracticaldev.s3.amazonaws.com/i/pweoc5olsfr2t7nrsqar.png"
    alt="Eclipse AEM Project example - Enter Node Name dialog for nt:component node"
  />
  <figcaption>
    New cq:component node
  </figcaption>
</figure>

**name**: `title`

#### Proxy Components

For the new `title` component, we're going to use the [Proxy Component Pattern](https://docs.adobe.com/content/help/en/experience-manager-core-components/using/developing/guidelines.html#proxy-component-pattern). For more info, [Create Proxy Components](https://docs.adobe.com/content/help/en/experience-manager-core-components/using/get-started/using.html#create-proxy-componentsinformation) contains further documentation on using core components.

Select the `title` component to enable its context in the JCR Properties panel. Select the green plus sign to insert a property.

<figure style="max-width:600px">
  <img 
    src="https://thepracticaldev.s3.amazonaws.com/i/vr5hbg33e6bw5e00se2g.png"
    alt="Eclipse AEM Project example - JCR Properties panel - insert property"
  />
  <figcaption>
    JCR Properties panel - insert a property
  </figcaption>
</figure>

Add following property to use the `title` core component version `v1` with the super-type.

**Name**: `sling:resourceSuperType`

**Value**: `core/wcm/components/title/v1/title`

>   Periodically export to the AEM JCR to verify and test your code changes.


Originally published at [jimfrenette.com/aem/eclipse-developer-tools](https://jimfrenette.com/aem/eclipse-developer-tools/)