5

I have been trying to upgrade my JHipster 5 application to use Java 10 but I can't get it to compile and process JPA static metamodels with Maven.

Apparently maven-compiler-plugin is not triggering hibernate-jpamodelgen in order to generate the JPA static metamodels.

In order to upgrade the project I have:

  • installed Oracle´s JDK 10.0.1
  • switched my pom.xml to <java.version>10</java.version>
  • upgraded maven-compiler-plugin to add java.xml.bind module (since it is not included by default as of Java 10) as follows:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <!-- fork is needed so compiler args can be used -->
                <fork>true</fork>
                <compilerArgs>
                    <arg>-J--add-modules</arg>
                    <arg>-Jjava.xml.bind</arg>
                </compilerArgs>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${mapstruct.version}</version>
                    </path>
                    <!-- For JPA static metamodel generation -->
                    <path>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-jpamodelgen</artifactId>
                        <version>${hibernate.version}</version>
                    </path>
    
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    

With this I am getting compilation failure when I run ./mvnw clean compile with no further detailed error message.

If I remove the <compilerArgs> tag from pom.xml and run the same command I get: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

I have followed the upgrade instructions provided here

Also, I made this example project available on GitHub

This is the commit changes where I upgraded to Java 10

djeison
  • 490
  • 2
  • 5
  • 20

2 Answers2

4

In order to register the solution here wishing to help others, here is what solved this issue:

It turns out it was some Java 9 compatibility problem with hibernate-jpamodelgen@5.2.16.Final. Once I upgraded to Hibernate version 5.3.1.Final it started to compile again.

I also had to solve JAXB dependencies following this answer.

djeison
  • 490
  • 2
  • 5
  • 20
  • I think this is going to be a further issue with Java 11 as the java.xml.bind module is removed completely. https://hibernate.atlassian.net/browse/HHH-12991 – codylerum Sep 25 '18 at 02:47
1

I had the same problem. Using Java 10, SpringBoot 2.0.3, Hibernate 5.3.1 .

What worked for me in Gradle, was to add javax.xml.bind to annotationProcessor as well :

annotationProcessor group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'

annotationProcessor group: 'org.hibernate', name: 'hibernate-jpamodelgen', version: '5.3.1.Final'

In this way, hibernate-jpamodelgen won't complain anymore about his missing javax.xml.bind dependency, since it's on the same group as him (annotationProcessor)

Robert
  • 5,278
  • 43
  • 65
  • 115