11

I use the Spring Dashboard in Eclipse to create the project. I've also tried creating it using Spring Initializr and tried both version 8 and 9 of java, but I still get this. Also tried to change the maven target. Run configuration, maven build is using the JavaSE1.8, jre 1.8.0.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RC2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>9</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Command:

javac version: 9.0.4

Apache Maven 3.5.2
Maven home: C:\Users\arito\Desktop\apache-maven-3.5.2\bin\..
Java version: 1.8.0_152, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_152\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Vio Ariton
  • 407
  • 1
  • 5
  • 17
  • 1
    you have to point your JAVA_HOME to a JDK 9, ot seems it points to a jdk 1.8: Java home: C:\Program Files\Java\jdk1.8.0_152\jre - is that above the "mvn -v" output? – wemu Feb 23 '18 at 15:24
  • Yeah I've done that. The error It's gone. Now I get **[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.RC2:run (default-cli) on project spring5-recipe-assigment-master: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException: javax.xml.bind.JAXBException** – Vio Ariton Feb 23 '18 at 16:12
  • 1
    thats a dependency / java 9 modules issue using search could have answered ;) look at this: https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j – wemu Feb 23 '18 at 19:47
  • for me changing java-version to 8 worked , it was 9 as it says in the error – devcodes Sep 24 '18 at 20:51

4 Answers4

1

I had to use to java 9 not 8.

I switched java environments in MacOS:

List java versions installed: /usr/libexec/java_home -V

Switch to java 9: export JAVA_HOME=`/usr/libexec/java_home -v 9.0.4`

(I had java 9 installed from before)

Source: How to set JAVA_HOME environment variable on Mac OS X 10.9?

Curtis Yallop
  • 6,696
  • 3
  • 46
  • 36
0

I solve this issue using the following configuration:

<build>
    <plugins>
        <!-- target Java 9 -->
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <!-- fork compilation and use the
                         specified executable -->
                <fork>true</fork>
                <executable>javac9</executable>
            </configuration>
        </plugin>
    </plugins>
</build>

There are another alternatives like Maven Toolchains or the mavenrc file.

JuanMoreno
  • 2,498
  • 1
  • 25
  • 34
0

This happened to me when I used Java 8 instead of Java 11 so I installed Java 11 and the error is gone.

essayoub
  • 713
  • 2
  • 8
  • 14
-1

Fatal error compiling: invalid target release: 9(same as yours) so i changed the red highlighted field in pom.xml of eclipse

  • Please do not use an image to describe what could otherwise be represented by text. – chb Feb 02 '19 at 18:09