Compiling Java 7 code via Maven

前端 未结 18 1235
夕颜
夕颜 2020-12-04 07:10

My pom file lists


  
    
        
            
                

        
相关标签:
18条回答
  • 2020-12-04 07:49

    You have to check Maven version:

    mvn -version
    

    You will find the Java version which Maven uses for compilation. You may need to reset JAVA_HOME if needed.

    0 讨论(0)
  • 2020-12-04 07:49

    {JAVA_1_4_HOME}/bin/javacyou can try also...

    <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <showDeprecation>true</showDeprecation>
                    <showWarnings>true</showWarnings>
                    <executable>{JAVA_HOME_1_7}/bin/javac</executable>
                    <fork>true</fork>
            </configuration>
        </plugin>
    
    0 讨论(0)
  • 2020-12-04 07:50

    Ok, I just solved this issue on my own too. It is more important your JAVA_HOME, if you don't have a lower or no version compared to source/target properties from the Maven plugin, you will get this error.

    Be sure to have a good version in your JAVA_HOME and have it included in your PATH.

    0 讨论(0)
  • 2020-12-04 07:55

    Could you try a newer plugin; on the maven site:

    <version>3.0</version>
    

    I saw the following too:

    <compilerVersion>1.7</compilerVersion>
    
    0 讨论(0)
  • 2020-12-04 07:56

    Diagnostics:

    You can see which java version Maven uses by running "mvn --version"

    Solution for Debian:

    The mvn script sets the JAVA_HOME env variable internally by looking for javac (which javac). Therefore, if you have multiple java versions installed concurrently, e.g. JDK 6 and JDK 7 and use the Debian Alternatives system to choose between them, even though you changed the alternative for "java" to JDK 7, mvn will still use JDK 6. You have to change the alternative for "javac", too. E.g.:

    # update-alternatives --set javac /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
    

    EDIT:

    Actually, an even better solution is to use update-java-alternatives (e.g.)

    # update-java-alternatives -s java-1.7.0-openjdk-amd64
    

    as detailed in https://wiki.debian.org/JavaPackage, because this will change all the alternatives to various Java tools (there's a dozen or so).

    0 讨论(0)
  • 2020-12-04 07:57

    Please check you pom.xml for the below tags

    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
    

    it should point the required jdk version

    0 讨论(0)
提交回复
热议问题