简体   繁体   English

当我使用“ mvn -v”时,为什么我的电脑中有两个java路径

[英]Why there are two java path in my PC when i use the “mvn -v”

When I use mvn spring-boot:run to run a Spring Boot project, I find if use the command in Cmd , it works. 当我使用mvn spring-boot:run运行一个Spring Boot项目时,我发现是否使用Cmd的命令,它可以工作。 but if I use it in Git Bash , it can't work. 但是如果我在Git Bash使用它,它将无法正常工作。

So I use java -version and mvn -v to view the Java and maven version. 因此,我使用java -versionmvn -v来查看Java和maven版本。

java -version give me the same result, but mvn -v result is different, as the picture shows: java -version给我相同的结果,但是mvn -v结果不同,如图所示: 终端输出1

And when I see my java path, I'm sure it's C:\\Program Files\\Java\\jdk1.8.0_151 当我看到我的java路径时,我确定它是C:\\Program Files\\Java\\jdk1.8.0_151

终端输出2

So I want to know, why there are two Java paths in my PC when I use mvn -v ? 所以我想知道,当我使用mvn -v时,为什么我的PC中有两个Java路径?

Both the java executable and Maven by default use the JDK that is specified in the $JAVA_HOME environment variable. 默认情况下, java可执行文件和Maven都使用$JAVA_HOME环境变量中指定的JDK。

You are executing java and Maven ( mvn ) in different environments ( cmd.exe in one case and Git Bash in the other case), so the most likely explanation is that $JAVA_HOME is set to different JDKs in the respective environments. 您正在不同的环境中执行java和Maven( mvn )(一种情况下执行cmd.exe ,另一种情况下执行Git Bash),因此最可能的解释是$JAVA_HOME被设置为各自环境中的不同JDK。

You can check the content of $JAVA_HOME with echo $JAVA_HOME . 您可以使用echo $JAVA_HOME检查$JAVA_HOME的内容。

暂无
暂无

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

相关问题 当我使用 mvn package 命令而不更改环境路径时如何指定 java 版本 - How to specify java version when I use mvn package command without change environment path 当我在由mvn:assembly构建的批处理中使用args4j时,为什么会发生java.lang.NoClassDefFoundError - Why occurs a java.lang.NoClassDefFoundError when I use args4j in a batch built by mvn:assembly 当我将Java用于Linux或Windows PC时。 它使用哪个JVM? 是j9还是JamVM或Squeak? - When i use Java for my Linux or Windows PC. Which JVM it use? Is it j9 or JamVM or Squeak? 为什么我的Java -version与我在mvn --version中看到的不同 - Why my java -version is different than what I see in mvn --version 当我使用`mvn hpi:run`时有一个ArrayIndexOutOfBoundsException - There is a ArrayIndexOutOfBoundsException when I use `mvn hpi:run` 为什么在尝试使用 android studio java web 服务器连接到我的 PC 上的服务器时出现错误? - Why when trying to connect using android studio java web server to my server on the pc i'm getting error? 当我安装了Oracle JDK 1.7时,为什么mvn 3.0.4在Ubuntu 13.04上使用-source 1.3? - Why does mvn 3.0.4 use -source 1.3 on Ubuntu 13.04 when I have Oracle JDK 1.7 installed? 当我可以在类路径中清楚地看到文件时,为什么Java编译器说我的文件不在类路径中? - Why does the Java compiler say my file was not found in the class path when I can clearly see it in the class path? 在 cmd 中运行“mvn -v”时不显示“Java Home” - "Java Home" not displayed on running "mvn -v" in cmd 当我通过USB将数据从PC流到Arduino时,为什么我的串口一直断开? - Why my serial port keep disconnecting when I stream data from PC to Arduino via usb?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM