In a custom Maven plugin, I add a file as resource by using the addResource of MavenProject.
This works well for JAR projects, but for EARs, I see that the relevant file is copied to target/classes and then ignored. It is not present in the EAR.
There is an earSourceDirectory property which I can probably use to "trick" Maven by setting it to target/classes but it seems like the wrong way.
How can I handle generated resources that should be packed into an EAR?
The Maven EAR plugin completely disregard all of the "resources" directories that can be set up for a given artifact. Instead, as you mentioned, it solely relies on the directory referenced by the
earSourceDirectoryproperty,src/main/applicationbeing the default value. (see https://maven.apache.org/plugins/maven-ear-plugin/ear-mojo.html#earSourceDirectory)Therefore, you have two choices: either change that property value to point to
target/classesas you proposed, or generate your files (as we did for one project) undersrc/main/applicationand then they will automatically be picked up by maven-ear-plugin.