I have a Java program that generates Java classes for my application.
Basically it takes in a simple spec for a class and generates a specialized
form of Java bean. I want to integrate this into my Maven pom.xml so
that if the input file is changed, Maven automatically generates the
new .java file before the compile phase of Maven.
I know how to do this trivially in make but I didn’t find anything
in the Maven doc with this functionality.
You didn’t provide much details on your code generation process but you could maybe simply invoke the code generator with the exec-maven-plugin (see the Examples section). The convention is to generate sources in
${project.build.directory}/generated-sources/<tool>. Then add the generated sources with the build-helper-plugin and itsadd-sourcesmojo. Bind every thing on thegenerate-sourcesphase.I’ll just show the build-helper stuff below:
You could also write a simple plugin to wrap your generator. In that case, have a look at the Guide to generating sources.
PS: I may have missed something, there is a kind of mismatch between my answer and the title of your question.