Expand my Community achievements bar.

Exclude pattern in filter.xml not working

Avatar

Level 3

Hi All,

I'm having trouble understanding a fundamental AEM concept and could use some guidance.
I have a configuration folder for the config.local.author runmode.
I want to exclude this folder from deployment so that any changes made via the OSGi Configuration Manager are retained and not overwritten during code deployments.

This is my filter.xml:

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/apps/fc2/osgiconfig">
<exclude pattern="/apps/fc2/osgiconfig/config.prod" />
<exclude pattern="/apps/fc2/osgiconfig/config.perf" />
<exclude pattern="/apps/fc2/osgiconfig/config.qa1" />
<exclude pattern="/apps/fc2/osgiconfig/config.qa2" />
<exclude pattern="/apps/fc2/osgiconfig/config.local.author" />
</filter>
</workspaceFilter>

I expect that the changes made on the local author instance via config mgr will be retained, and the configuration provided in the code should not overwrite them during deployment.
However, it is getting overwritten with the value for that config in code base. 
NOTE: There is no other module which is including /apps/fc2/osgiconfig/config.local.author.

Screenshot 2025-05-09 at 19.56.18.png

7 Replies

Avatar

Level 3

To rule out the possibility of exclude patterns matching only the specified directories and not their contents, I've also tried 

<exclude pattern="/apps/fc2/osgiconfig/config.local.author(/.*)?"/>

This creates another scenario, as the crx now has two files under /apps/fc2/osgiconfig/config.local.author
1. nt:file which is the modified version via config mgr
2. sling:OsgiConfig which is coming via code base even though it should be excluded as per the excluded pattern

Avatar

Community Advisor

Hi @MeenuRajput ,

Try below solution:

1. Update the filter.xml File

The first step is to ensure that the exclude pattern in your filter.xml file is correctly defined. When using regex, special characters like the period (.) must be escaped to ensure proper matching. Here’s the corrected pattern:

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/apps/fc2/osgiconfig">
        <exclude pattern="/apps/fc2/osgiconfig/config\.local\.author(/.*)?"/>
    </filter>
</workspaceFilter>

 

Escaped dot (\.): The . character is a regex wildcard, so we need to escape it to match the literal . in config.local.author.

Recursive exclusion ((/.*)?): This ensures that not only the config.local.author folder but also any files or subfolders within it will be excluded.

By making this change, the config.local.author folder and its contents will be excluded from the deployment process.


2. Remove the Folder from the Codebase

If the folder /apps/fc2/osgiconfig/config.local.author/ still exists in your project’s source code, it will be included in the package, even if excluded in filter.xml. This is why you need to ensure it is physically removed from your source directory.

Steps:

Delete the folder: Remove /apps/fc2/osgiconfig/config.local.author/ from the src/main/content/jcr_root/ directory.

Check for .content.xml or OSGi config files: If there are any .content.xml or OSGi configuration files inside config.local.author, remove them as well to prevent their inclusion during deployment.


3. (Optional) Exclude via Maven Build Configuration

If, for any reason, you need to keep the folder in your codebase (for example, for documentation purposes or local development), you can ensure that it is excluded at build time using the Maven build configuration.

In your pom.xml file, configure the content-package-maven-plugin to exclude this folder from the packaged ZIP:

<plugin>
    <groupId>com.day.jcr.vault</groupId>
    <artifactId>content-package-maven-plugin</artifactId>
    <version>1.1.6</version>
    <configuration>
        <filesExcludes>
            <file>**/config.local.author/**</file>
        </filesExcludes>
    </configuration>
</plugin>

This will exclude the config.local.author folder from the final package, even if it is still present in your source.

4. Validate the Build

After implementing the above changes, follow these steps to ensure everything is working correctly:

  - Build the project: Run mvn clean install to rebuild your project.

  - Inspect the ZIP file: Once the build is complete, unzip the generated package located in the target/ directory.

  - Confirm exclusion: Check that the config.local.author folder is not present in the unzipped package. If it’s absent, your exclusion pattern is correctly configured.

Regards,
Amit

 

Avatar

Level 3

Hi Amit, 

1. I tried using this regex, but it gives the same result, /apps/fc2/osgiconfig/config.local.author node has t :
 nt:file as well as sling:OsgiConfig which is coming from the code base. 
2. I can remove the files and folders from the codebase to exclude them from deployment, but that makes me question the purpose of filter.xml, as it doesn’t seem to have any effect in this case.

I'm close to identifying the cause of this unusual behavior but I need your help. 
Although it's not the ideal approach, if I manually update the sling:OsgiConfig node directly in CRX (instead of using the ConfigMgr console), the nt:file node isn't created. In that case, the regex works correctly, and the value is not overwritten after code deployment.

The issue occurs only when the path /apps/fc2/osgiconfig/config.author.local in CRX has a nt:file node after the config is updated via the ConfigMgr console and after deployment it keeps the config file (update version via config mgr) and config node generated via code 



Avatar

Level 4

Hi @MeenuRajput ,

According to the filters you have written they include /apps/fc2/osgiconfig, but exclude these subfolders including config.local.author.

 

However, configs are still being deployed, which likely means:-

  • The content is still included in the ZIP (check /target folder and unzip the package to verify).
  • Another module or filter.xml might be including it inadvertently.
  • A .content.xml inside config.local.author might still exist and get picked up.

You can try below things:-

  • Keep your filter.xml exclusion as it is.
  • Check all other filter.xml files in the project, make sure none of them includes /apps/fc2/osgiconfig/config.local.author.
  • Ensure no .content.xml or other file inside config.local.author is included in the codebase.
  • After build (mvn clean install), unzip your package and confirm config.local.author is not inside.
  • Make sure no bundle or OSGi component programmatically registers the config again at runtime.

If all these are addressed, the config on the local author instance should no longer be overwritten on deployment.

Avatar

Level 3

Thanks for your response. 

  • Check all other filter.xml files in the project, make sure none of them includes /apps/fc2/osgiconfig/config.local.author. - There is no other module with same path in filter.xml
  • Ensure no .content.xml or other file inside config.local.author is included in the codebase. - There are just two .xml files. 
  • After build (mvn clean install), unzip your package and confirm config.local.author is not inside. - Upon unzipping package after latest build, it still shows the excluded folder and its files.
  • Make sure no bundle or OSGi component programmatically registers the config again at runtime. - There is no such bundle that can register the config again.

    I updated the exclude pattern: 
    <exclude pattern="/apps/fc2/osgiconfig/config.local.author(/.*)?"/>

    This creates another scenario, as the crx/de now has two files under /apps/fc2/osgiconfig/config.local.author :
    1. nt:file which is the modified version via config mgr
    2. sling:OsgiConfig which is coming via code base even though it should be excluded as per the excluded pattern

    Screenshot 2025-05-09 at 21.48.02.png




Avatar

Community Advisor

Hi @MeenuRajput ,

we can explicitly mention all the child folder as root so that we don't need to exclude instead of mentioning osgiconfig folder as root

<filter root="/apps/fc/osgiconfig"/>
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
	<filter root="/apps/fc/config/rewriter/versioned-clientlibs"/>
	<filter root="/apps/fc/osgiconfig/config"/>
	<filter root="/apps/fc/osgiconfig/config.author"/>
	<filter root="/apps/fc/osgiconfig/config.author.dev"/>
	<filter root="/apps/fc/osgiconfig/config.author.preprod"/>
	<filter root="/apps/fc/osgiconfig/config.author.prod"/>
	<filter root="/apps/fc/osgiconfig/config.publish"/>
	<filter root="/apps/fc/osgiconfig/config.publish.qa"/>
	<filter root="/apps/fc/osgiconfig/config.author.qa"/>
	<filter root="/apps/fc/osgiconfig/config.publish.qa"/>
	<filter root="/apps/fc/osgiconfig/config.author.qa"/>
	<filter root="/apps/fc/osgiconfig/config.publish.qa"/>
</workspaceFilter>

Thanks

Avatar

Administrator

Hi @MeenuRajput,

Did the shared solution help you out? Please let us know if you need more information. Otherwise kindly consider marking the most suitable answer as ‘correct’.

If you've discovered a solution yourself, we would appreciate it if you could share it with the community.