Why Maven uses JDK 1.6 but my java -version is 1.7

前端 未结 9 2060
一个人的身影
一个人的身影 2020-11-28 18:01

I\'m new to maven, and also to MacOS.

I have setup maven in my terminal, and when getting the version settings (using mvn -v) it seems it uses JDK 1.6,

相关标签:
9条回答
  • 2020-11-28 18:43

    You can also explicitly tell maven which java version to compile for. You can try adding the maven-compiler-plugin to your pom.

    <project>
      [...]
      <build>
        [...]
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
              <source>1.7</source>
              <target>1.7</target>
            </configuration>
          </plugin>
        </plugins>
        [...]
      </build>
      [...]
    </project>
    

    If you imported a maven project into an IDE, then there is probably a maven setting in your IDE for default compiler that your maven runner is using.

    0 讨论(0)
  • 2020-11-28 18:45

    Get into

    /System/Library/Frameworks/JavaVM.framework/Versions
    

    and update the CurrentJDK symbolic link to point to

    /Library/Java/JavaVirtualMachines/YOUR_JDK_VERSION/Contents/
    

    E.g.

    cd /System/Library/Frameworks/JavaVM.framework/Versions
    sudo rm CurrentJDK
    sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/ CurrentJDK
    

    Now it shall work immediately.

    0 讨论(0)
  • 2020-11-28 18:47

    For Eclipse Users. If you have a Run Configuration that does clean package for example.

    In the Run Configuration panel there is a JRE tab where you can specify against which runtime it should run. Note that this configuration overrides whatever is in the pom.xml.

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