maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kyle Marek <>
Subject Custom resource filters; multiple filters
Date Mon, 29 Jul 2019 21:23:11 GMT
Hello Maven Users,

Some context: We are developing a webapp which utilizes React for our UI 
component. It is an known/open issue that React applications need to 
know their deployment location when built, because resource paths are 
embedded into the build output.


We've worked around the issue by setting our deployment path to some 
constant like PUBLIC_URL_REPLACE_ME and then using a Response filter to 
substitute the the value of request.getContextPath() of the relevant 
resources at run time.

We'd like to instead substitute JSP like "<%=request.getContextPath()%>" 
at build time instead of using a Response filter at run time. However, 
we also need to place a JSP page directive at the beginning of our 
resources to correct Content-Type and either disable or escape EL and 
such, so this isn't as simple as configuring React to use "@PUBLIC_URL@" 
and substituting with the built-in Maven Resources filtering.

I understand maven-resources-plugin supports the usage of one or more 
custom resource filters,


but it is not clear to me how this is intended to work, or if its design 
even accomplishes the developers' intent.

For example, I would expect to use the Wrapper design pattern to wrap an 
InputStream or OutputStream as it is used to copy/filter the file 
contents to the destination during copy-resources. While this design 
pattern is supported by the involved MavenFileFilter [1], there is no 
code path from a custom MavenResourcesFiltering [2] implementation to 
add a FilterWrapper to the list [3].

I would expect to use mavenResourcesExecution.addFilterWrapper() in 
filterResources() of my custom MavenResourcesFiltering implementation, 
but custom filters are executed *after* DefaultMavenResourcesFiltering [4].

While the added FilterWrapper would be available to the custom 
MavenResourcesFiltering implementations, one of the implementations 
would need to *duplicate* the logic of DefaultMavenResourcesFiltering 
and do a *second* copy of all of the resources in order to correct the 
lack of custom FilterWrappers when DefaultMavenResourcesFiltering was 
executed. I do not think this approach is sensible, or the intention of 
the custom resources filters support.

Another approach I've seen involves extending 
DefaultMavenResourcesFiltering or DefaultMavenFileFilter with another 
class that takes on the same Plexus hint="default" [5] [6], but this 
approach doesn't even utilize the custom resources filter support 
(you're basically overriding an internal Maven component when doing 
this), nor can it compound unrelated filters.

In all cases, there does not appear to be a way configure custom 
resources filters per execution or per resource directory defined in the 
POM, and information about the resource, like file name, are not passed 
to FilterWrappers (which complicates my ability to correctly set 
Content-Type in the JSP page directive).

So... are these issues just untested oversights and the existing custom 
resources filters support is useless, or am I misunderstanding how they 
are *supposed* to be utilized?

Where do we (either our project, or Maven) go from here? Should this be 
brought to Maven Developer List for collaboration on improving the design?

Thank you,

Kyle Marek















To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message