Removing samples from an AEM Maven project
Last update: Sun Mar 23 2025 00:00:00 GMT+0000 (Coordinated Universal Time)
- Topics:
- AEM Project Archetype
CREATED FOR:
- Beginner
- Developer
Learn how to clean-up and remove generated sample code from an AEM Project generated by the AEM Project Archetype.
Transcript
So I just want to quickly show you how you can clean up some of the example or sample code that the AEM project archetype adds to generated projects. So this project was generated using version 30 of the AEM Maven project archetype. And we’re just going to go in and get rid of some of these sampler examples, which can absolutely be helpful if you’re getting started with AEM and playing around with it. But you certainly don’t want the sample code to end up in your production code base or deployed to production itself since it is sample code and you never want sample code on production. So let’s get started. First we’ll go to core and this is where the Java code resides in the project. So it’s going to generate the OSJ bundle and you can see that the Maven archetype has generated a bunch of sample classes for us. And so we don’t want any of these. We are going to simply go through and delete all of these packages as well as the Java code Let’s go ahead and delete the serverless. It’s the last one. Next we want to head over to tests and since there are tests for each of the files we just deleted we need to get rid of those tests as well. Otherwise the Maven build would of course fail. So let’s go ahead and delete all of our tests And now we’ve cleaned up our core Java code. Next let’s head over to the UI apps project. So this is going to install into the slash apps folder and usually contains things like component definitions or other configurations. So let’s head in here and you’ll see that under apps your project name and components there are a bunch of components listed here. So all but one of these are core component proxies and you’ll want to keep these because you’ll actually be using these to build out your AM site. However there is this hello world component that is added as a sample component and we are going to want to delete this as well. And do note that this component actually references the sling model that we deleted from the core project. Alright so we’ve gotten rid of our hello world so we should be good with our components. And now let’s head down to the UI frontend project. And this contains the frontend code so the CSS or JavaScript used to style our components as well as provide any client-side behavior. So if we drill into source webpack components and scroll down you’ll see that we have some JavaScript as well as CSS or in this case a CSS that support our hello world component we just deleted. So let’s go ahead and get rid of these as well. And note that all of these other files are in support of those core component proxies so we’ll want to keep them. Last thing we want to do in UI frontend is head over to the hello world component. And you can see we have a sample here and delete that as well. And do note that with the deletion of this hello world component from the static file when you do open this up to develop against it will appear quite empty. Alright the last thing we want to do is head over into UI content. This contains any of the content definitions that are part of this project. So if we go into source main content, go into JCR which represents the JCR root, go to content, go to our site, click into USEN and click on the .content.xml folder. Here we have the XML definition for our CQ page that represents our home page. And similar to the static index.html if we scroll down we’re going to see a sample of the hello world component embedded in here. And since we’ve deleted this component from our project it will no longer render. So let’s just go ahead and remove this as well. Alright so that should about do it. We’ve cleaned up all of our samples and example code that we wouldn’t want deployed to our production instance. Before we go I do want to call out these two projects here, IT tests as well as UI tests. So if we click into these we can actually see that the Maven archetype has generated some sample tests for us. And secondly these tests actually ensure and validate that custom code that you may have added to your project and deployed to AEM aren’t breaking out of the box AEM functionality. So it is nice to keep these in your project to avoid accidents. And if we go into the UI tests under the specs you can see that there are a handful of specs here as well that help validate that some of the out of the box functionality isn’t broken. So that’s about it. Let’s just run a quick Maven clean verify and just make sure that our project still builds and we don’t have any issues based on our deletions here. Alright so it looks like the build succeeded. The last thing we want to do of course is commit our changes to git. And now you should be ready to go and start adding your production code to your project.
Resources
Commands
The following commands can be executed to remove the generated sample files from the AEM Maven Project:
rm -rf core/src/main/java/com/adobe/aem/wknd/examples/core/filters \
rm -rf core/src/main/java/com/adobe/aem/wknd/examples/core/listeners \
rm -rf core/src/main/java/com/adobe/aem/wknd/examples/core/models \
rm -rf core/src/main/java/com/adobe/aem/wknd/examples/core/schedulers \
rm -rf core/src/main/java/com/adobe/aem/wknd/examples/core/servlets \
rm -rf core/src/test/java/com/adobe/aem/wknd/examples/core/* \
rm -rf ui.apps/src/main/content/jcr_root/apps/wknd-examples/components/helloworld \
rm -rf ui.frontend/src/main/webpack/components/_helloworld.js \
rm -rf ui.frontend/src/main/webpack/components/_helloworld.css
Edits
Remove the <div class="helloworld" ...></div>
from:
ui.frontend/src/main/webpack/static/index.html
Remove the <helloworld>
component instance definition from:
ui.content/src/main/content/jcr_root/content/wknd-examples/us/en/.content.xml
recommendation-more-help
4859a77c-7971-4ac9-8f5c-4260823c6f69