hibernatemaven-2hibernate3hbm2java

Maven doesn't compile target/hibernate3/generated-sources


Can someone tell me how to configure maven for it also to compile sources from the target/hibernate3/generated-sources directory? I have already read this and other posts but they don't seem to solve my problem (which indeed seems trivial).

I have used the bottom-up approach hibernate configuration for cfg.xml, hbm.xml and POJO generation (i.e. auto-generated the complete hibernate configuration out of an existing database schema). I'm also only using standard maven and hibernate3-plugin directory layouts. Yet, when executing mvn compile in the command-line while my sources are in the src/main/java and the generated sources in /target/hibernate3/generated-sources only the ones from src/main/java get compiled and copied into target/classes. I wouldn't like to generate sources into src/main/java as I'd like mvn clean to clean them.

I'd like to solve the problem using command-line, plugins and pom.xml only. Is there a way to configure maven-compiler-plugin to do so? Or is there another way?

Regards and thanks for any help.


Solution

  • The convention is to generate code in target/generated-sources/<generator> so in your case, I would generate sources in target/generated-sources/hibernate3 (it's sad the hibernate3 plugin doesn't follow this convention by default). Anyway, things should work and actually, the POM I posted in this previous answer does (I re-ran my sample project and it definitely works). Could you be a victim of MHIBERNATE-104? Honestly, I'm confused.

    As a workaround, you could use the Build Helper Maven Plugin and its build-helper:add-source goal to add your directory as source directory. See the Usage page for a configuration example.


    I'm using exactly the pom you proposed here, just not plugged into the default build lifecycle (without executions).

    That must be the cause of the problem: if hibernate3:hbm2java isn't part the build lifecycle, it doesn't get the opportunity to register the output directory as source folder. So Maven isn't aware of it during the "normal build" and will just ignore it.