Maven can't compile java 1.8

后端 未结 8 1380
旧巷少年郎
旧巷少年郎 2021-02-04 03:39

I\'m trying to use maven to build a jar but I keep getting the error

ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 
(d         


        
相关标签:
8条回答
  • 2021-02-04 04:03

    If anybody has Eclipse Kepler SR2 and has an issue with Java 1.8 while building project with Maven, try to go to Eclipse Marketplace and search for plugin called Java 8 support for m2e for Eclipse Kepler SR2 this helped me, and now Maven compiles Java 1.8 source without problem.

    0 讨论(0)
  • 2021-02-04 04:08

    Maven relies on the JAVA_HOME environment variable being set. Set it according to your OS and re-run your build.

    Edit: Use export to set the variable.

    export JAVA_HOME=/path/to/java
    
    0 讨论(0)
  • 2021-02-04 04:10

    you can try configuration in compiler plugin. Its working on my local

          <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <executable><!--path-to-your-java8-home-directoru--></executable>
                    <compilerVersion>1.8</compilerVersion>
                </configuration>
            </plugin>
    
    0 讨论(0)
  • 2021-02-04 04:12

    As a MacOS user, open a Terminal and create or edit a file .bash_profile (in the directory of your user home) and put the following snippet there:

    export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
    

    Save that file and reopen a Terminal instance. If you execute export as a command there, you should see a valid JAVA_HOME with the location of your JDK 8 installation. Restart your IDE afterwards and maven should be able to build you nice java target 1.8 code.

    0 讨论(0)
  • 2021-02-04 04:17

    Yes it seems a bug in the maven-compiler-plugin.When I upgraded from 3.1 to 3.5.1, it works.

    0 讨论(0)
  • 2021-02-04 04:24

    I'm not sure but can you try to update your maven.plugin version

    try

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                </configuration>
            <version>3.6.1</version>
    </plugin>
    
    0 讨论(0)
提交回复
热议问题