java命令行在Mac上需要JDK吗? [英] java command line requires JDK on Mac?
问题描述
我已经从Oracle官方站点在MacOS X 10.10上安装了JRE 1.8.我安装的文件是jre-8u66-macosx-x64.dmg
.令我惊讶的是,java
命令说我需要JDK才能工作.
I've installed JRE 1.8 on MacOS X 10.10 from the official Oracle site. The file I've installed was jre-8u66-macosx-x64.dmg
. To my surprise, the java
command says I need JDK for it to work.
有没有一种方法可以在Mac上不使用JDK的情况下从命令行执行jar?如果没有,那有什么运行Java代码的选项(浏览器小程序除外)?
Is there a way to execute a jar from the command line on Mac without JDK? If not, what options for running Java code are there (other than browser applets)?
从命令行调用java -v
时,我得到以下输出:
when invoking java -v
from the command line, I get the following output:
不存在Java运行时,要求安装.
No Java runtime present, requesting install.
和一个警告窗口,其中显示:
and an alert window, which says:
要使用"java"命令行工具,您需要安装JDK.
To use the "java" command-line tool you need to install a JDK.
另一个数据点:/Library/Java/JavaVirtualMachines文件夹为空.相反,在/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
下有一些内容.它甚至在/bin/下有一个命令行java
.用-version
运行它可以得到:
One more data point: the folder /Library/Java/JavaVirtualMachines is empty. Instead, there's stuff under /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
. It even has a command-line java
under /bin/. Running it with -version
gives:
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
我想知道我是否可以以某种方式将其用于CLI.
I wonder if I can somehow leverage that one for CLI..
推荐答案
如果重新安装不能解决问题,则可以将$ JAVA_HOME设置为java的安装位置:
In the case a re-install does not fix the problem, you could set $JAVA_HOME to the location java is installed:
export JAVA_HOME=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
之后,java -v
应该可以工作,但是您必须为每个新的终端窗口执行此操作,或者根据您使用的外壳将其添加到.bash_profile
或其他文件中.
After that, java -v
should work, but you'll have to do it for every new terminal window, or add it to .bash_profile
or other file depending on the shell you use.
这篇关于java命令行在Mac上需要JDK吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!