简体   繁体   English

为什么 Maven 在从 Fish 运行时使用错误的 JDK 版本?

[英]Why does Maven use the wrong JDK version when running from Fish?

I run macOS Sierra, and have installed the Fish shell ( https://fishshell.com/ ).我运行 macOS Sierra,并安装了 Fish shell ( https://fishshell.com/ )。

When I try to build a Maven project, it now gives me当我尝试构建 Maven 项目时,它现在给了我

Fatal error compiling: invalid target release: 1.8 ->

... which means that it has picked up an older JDK which it tries to use to build my Java 8 project with. ...这意味着它选择了一个旧的 JDK,它试图用它来构建我的 Java 8 项目。

This is made obvious by running mvn -version :通过运行mvn -version明显mvn -version这一点:

...
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
...

But I have JAVA_HOME set correctly, echo $JAVA_HOME in both shells give me:但我有JAVA_HOME设置正确, echo $JAVA_HOME两弹给我:

/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home

and java -version gives mejava -version给了我

java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b16)

and javac -version :javac -version

javac 1.8.0_112

echo $PATH gives the same result in both shells (except that in Bash, the directories are separated by : ; in Fish, a space echo $PATH在两个 shell 中给出相同的结果(除了在 Bash 中,目录由:分隔;在 Fish 中,一个空格): ):

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin

I have configured maven-compiler-plugin to for 1.8:我已将maven-compiler-plugin配置为 1.8:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.6.0</version>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <encoding>${project.build.sourceEncoding}</encoding>
  </configuration>
</plugin>

Why does Maven insist on using the 1.6 JDK?为什么Maven坚持使用1.6 JDK? The same project builds fine, with the correct 1.8 JDK, when running through Bash.通过 Bash 运行时,使用正确的 1.8 JDK 可以很好地构建相同的项目。

如果您运行的是旧版本的 maven,请尝试更新到最新版本 (3.5.0),例如通过自制软件 ( brew install maven )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM