I had real fun getting the metamodel generator, eclipse, and maven to coordinate on this. Here is what you need to do when using m2eclipse:
Add the following to your POM file:
Code:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/generated/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
Notice that I am generating sources to the directory src/generated/java. You don't want even generated source code to go to target. Only the compiled classes should go to target.
Open the project properties in eclipse. Go to Java Compiler/Annotation Processing
Enable annotation processing and set the generated source directory to src/generated/java.
Under factory path, you will need to reference the metamodel jar and any dependencies.
As far as I can tell, there is no way to get maven to generate this configuration.
Now, right click on the project and select Maven/Update Project Configuration. This should add a new source directory to you your project called generated/java. You should see your metamodel there.
You do not want to use your main/java directory as the target of the metamodel generator as it will delete all of your source files!
Ted Young