Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work with a bundle in eclipse when it was downloaded from AEM

I downloaded a zip from a running instance of AEM from package manager - http://localhost:4502/crx/packmgr/index.jsp. The zip file, when extracted contains, jcr_root and META-INF.

I would like to build some functionality on top of this zip file. So I'm wondering if there is a way to work with this file in eclipse? However, there are no pom.xml files in this zip folder. So I can't just import it in Eclipse. I have AEM developer tools downloaded for Eclipse.

Is there a guide available that explains how to do this? The zip file contains some Java files and I would like to make changes to those Java files and re-package, re-deploy, so that I can test my changes.

I tried using Adobe Brackets (with AEM extension) but it only works well for JS or JSP changes...not for JAVA files.

Update

After @Gabriel's comment, this is my understanding of how I need to move around from the package I downloaded to the new project created via eclipse.

enter image description here

After doing the above

Here is what the new eclipse project looks like after I've copy/pasted everything

enter image description here

Contents of filter.xml from downloaded package

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/etc/designs/delta"/>
    <filter root="/apps/delta"/>
    <filter root="/content/delta"/>
    <filter root="/content/dam/delta"/>
    <filter root="/content/usergenerated/content/delta"/>
    <filter root="/apps/foundation/components/parsys"/>
</workspaceFilter>

Based on above I changed two filter.xml in following locations

/myproj.ui.apps/src/main/content/META-INF/vault/filter.xml

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/apps/myproject">
        <exclude pattern="/apps/myproject/install" />
    </filter>
    <filter root="/apps/foundation/components/parsys" />
    <filter root="/etc/designs/delta"/>
</workspaceFilter>

/myproj.ui.content/src/main/content/META-INF/vault/filter.xml

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/content/myproject"/>
    <filter root="/content/dam/myproject"/>
    <filter root="/content/usergenerated/content/delta"/>
</workspaceFilter>

Doing clean/publish seemed to have no effect as I didn't see anything in CRX or localhost:4502/siteadmin after doing clean/publish. So I tried to install manually.

For that I did Run as -> Maven Install on myproj (which builds the following zip files)

~/Documents/workspace/myproj $ tree | grep "zip"
│       ├── myproj.ui.apps-0.0.1-SNAPSHOT.zip
        ├── myproj.ui.content-0.0.1-SNAPSHOT.zip

When I upload & install these two files to CRX I see the following:

enter image description hereenter image description here

However, this also seems to not be having any effect because I don't see anything in localhost:4502/siteadmin and when I visit localhost:4502/content/myproj I get an error

``

BTW this is what I see under localhost:4502/siteadmin

enter image description here

Update 2

After going through everything again I was able to create the eclipse project and was successful in clean/publishing. However, changes to JAVA files aren't being reflected when I do clean/publish.

@Gabriel mentioned that

PROJECT.core for Java bundles (these will become interesting as soon as you want to add Java code)

I have java files already that are in PROJECT.ui.apps as shown in the image below

enter image description here

If I make a change to this JAVA file and clean/publish, my changes aren't being reflected in AEM. Is there something else that needs to be done to be able to change and publish JAVA code? or How can I make changes to JAVA files and test that on AEM?

like image 274
birdy Avatar asked Apr 17 '15 12:04

birdy


People also ask

What is the use of bundle in AEM?

AEM uses Apache Felix implementation. A bundle is the smallest unit of the modularization which means in OSGi, a software component is a bundle. In AEM, along with out of the box bundles, we can also install our custom bundles very easily. So without further ado, let us start creating an OSGi bundle.


1 Answers

You can use the New Project feature to create the right structure for you:

  • In Eclipse do File > New > Project...
  • Choose AEM > AEM Sample Multi-Module Project > Next
  • Pick the latest Archetype version
  • Enter the Name, Group Id, and Artefact Id > Next
  • Either Add to existing server if there's already one and pick the Location, else choose Setup new server and fill all fields > Finish
  • Wait for Eclipse to finish setting up everything

You now have following projects created for you, which will allow healthy separation of concerns:

  • PROJECT.ui.apps for /apps and /etc content
  • PROJECT.ui.content for /content that is authored
  • PROJECT.core for Java bundles (these will become interesting as soon as you want to add Java code)
  • PROJECT.it.launcher and PROJECT.it.tests for integration tests (you can ignore these as long as you don't run any integration tests)

First, replace the content of your PROJECT.ui.apps project with the apps and etc folders of your package:

  • In the Project Explorer panel, unfold PROJECT.ui.apps > src > main > content > jcr_root > apps
  • Right-click on the apps folder and choose Show In > System Exporer
  • Delete the apps and etc folders that you should now be seeing and place here the apps and etc folders of your of your content package
  • In Eclipse, right-click on the PROJECT.ui.apps project and choose Refresh

Then do the same for the PROJECT.ui.content and replace it's content folder with the one of your package:

  • In the Project Explorer panel, unfold PROJECT.ui.content > src > main > content > jcr_root > content
  • Right-click on the deeper content folder and choose Show In > System Exporer
  • Delete the content folder that you should now be seeing and place here the content folder of your of your content package
  • In Eclipse, right-click on the PROJECT.ui.content project and choose Refresh

Now you have to update the filter.xml files of these two projects to correspond to the content of your content package. For that, open the META-INF/vault/filter.xml file of your content package in a separate text/code editor.

This is an example of how your filter.xml file can look:

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/apps/foo"/>
    <filter root="/apps/foundation/components/bar"/>
    <filter root="/etc/designs/foo"/>
    <filter root="/content/foo"/>
    <filter root="/content/dam/foo"/>
    <filter root="/content/usergenerated/content/foo"/>
</workspaceFilter>

As for the content of your package that got split into two projects, you'll also have to split these filter rules into two and update accordingly the filter.xml files of the two projects.

  • In Eclipse, open PROJECT.ui.apps/src/main/content/META-INF/filter.xml
  • Replace the content of the <workspaceFilter> element with the rules of your package that start with /apps and /etc
  • Then open PROJECT.ui.content/src/main/content/META-INF/filter.xml
  • Replace the rules with the ones of your package that start with /content

Based on the above example, this is how the filter.xml of PROJECT.ui.apps would look:

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/apps/foo"/>
    <filter root="/apps/foundation/components/bar"/>
    <filter root="/etc/designs/foo"/>
</workspaceFilter>

And the one of PROJECT.ui.content:

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/content/foo"/>
    <filter root="/content/dam/foo"/>
    <filter root="/content/usergenerated/content/foo"/>
</workspaceFilter>

Make sure to Save all your changes. You should now be done, and can synchronize that new content to your AEM instance.

  • In the Servers panel, make sure that your connection is [Started], and if not start it
  • Click on the Clean and Publish icon (the last one)

Once done, you should have your package running on your instance, and on save, any change automatically get synchronized to the instance.

If you wish to re-build a package out of your project:

  • Right-click on the PROJECT.ui.apps or PROJECT.ui.content and choose Run As > Maven Install
  • You now have a target folder that has been created with your package inside (called for e.g. PROJECT.ui.apps-0.0.1-SNAPSHOT.zip).
like image 68
Gabriel Walt Avatar answered Sep 23 '22 12:09

Gabriel Walt