I have a Maven project set up that has a parent and two child modules:
parent
business
support
All of my JPA entities are in the support module. I've decided I want to use JPA metamodel classes to provide type safety when I use the Criteria API. I made changes to the pom.xml for the support module (see below) and the metamodel classes are being created correctly in support/target/metamodel
when I build from the command line using mvn clean install
. Builds work and deployable artifacts work when deployed.
The issue is that when I follow the instructions here (which mirrors many other places) on how to set up Eclipse to build the metamodel classes, Eclipse doesn't seem to do anything. It creates the support/target/metamodel directory but there's never anything in it. I've cleaned inside Eclipse, from the command line using mvn clean
, done Maven->Update Project multiple times but nothing seems to work.
What am I missing?
Here's what my support project's properties look like.
The relavant section of my support module's pom.xml is:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>target/metamodel</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/metamodel</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Version information:
Red Hat JBoss Developer Studio Version: 10.2.0.GA Build id: GA-v20161125-1418-B55 Build date: 20161125-1418
Java 1.8.0_112
Maven (command line): 3.3.9
Maven (Eclipse - m2e): 1.7.120161104-1805 embedded version 3.3.9
This is the setup that has worked for me.
I did not use the org.bsc.maven:maven-processor-plugin, rather set up the maven-compiler-plugin for annotation processing. The issues mentioned in the instructions , ie MCOMPILER-62 and MCOMPILER-66 , are now closed, so I see no reason why to bother with the org.bsc.maven:maven-processor-plugin.
Another notable difference is the "Factory Path", in the Eclipse configuration.
A minimal setup to get started. Note the maven-compiler-plugin configuration.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>scratch</groupId>
<artifactId>jpa</artifactId>
<version>0.1.0-SNAPSHOT</version>
<properties>
<version.plugin.maven.compiler>3.5</version.plugin.maven.compiler>
<version.hibernate>5.2.5.Final</version.hibernate>
</properties>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.plugin.maven.compiler}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<optimize>true</optimize>
<debug>true</debug>
<encoding>UTF-8</encoding>
<annotationProcessors>
<annotationProcessor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</annotationProcessor>
</annotationProcessors>
<annotationProcessorPaths>
<path>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${version.hibernate}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${version.hibernate}</version>
</dependency>
</dependencies>
</project>
You may want to run it once by hand or download hibernate-jpamodelgen by hand (eg mvn dependency:get -Dartifact=org.hibernate:hibernate-jpamodelgen:5.2.5.Final
), so that the JAR is available for the Eclipse configuration.
target/generated-sources/annotations/
(this is where Maven puts them by default)hibernate-jpamodelgen
version will probably vary):
org/hibernate/hibernate-jpamodelgen/5.2.5.Final/hibernate-jpamodelgen-5.2.5.Final.jar
javax/persistence/persistence-api/1.0.2/persistence-api-1.0.2.jar
This will work for eclipse 2019-06 or later versions:
According to Jboss documentation, it is not required to explicitly set the processor plugin, since the metamodel classes are created automatically on Maven build in \\target\\generated-sources\\annotations project's folder (since JDK 1.6).
Thus, you only need to make sure the Annotation Processing refers to this target folder, as in here:
in case you are going to use a recent eclipse with Java 11, you will meet the issue that the javamodel is not generated even specifying the hibernate-jpamodelgen in annotation processing of eclipse. If you check the error tabs you will see this: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
this is due the fact that it has been removed in Java 11, so to fix it you should add also the jar jaxb-api on the factory path with hibernate-jpamodelgen.
I leave this here for anyone that could meet the same problems I had (and for me when I search again and have forgot about this)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.