简体   繁体   English

如何查找是否在Mac中安装了jre或jdk,以及是否未使用Shell脚本安装jre

[英]How to find if jre or jdk is installed in Mac and if not install jre using shell script

Before I install a Java application on any client machine (Mac OSX >10.5), I would like to first see if either JDK or JRE is installed already in the machine. 在任何客户端计算机(Mac OSX> 10.5)上安装Java应用程序之前,我想首先查看计算机中是否已安装JDK或JRE。 If JRE/JDK is not present, I want to install JRE in that machine and then proceed with the actual application installation. 如果不存在JRE / JDK,我想在该计算机上安装JRE,然后继续进行实际的应用程序安装。

Was wondering how to write a shell script to find if Java is already installed in the client machine, and conditionally proceed with rest of the installation. 想知道如何编写一个shell脚本来查找客户端计算机中是否已经安装了Java,并有条件地进行其余的安装。 Any pointers to built-in tools/ sample code will help. 指向内置工具/示例代码的任何指针都将有所帮助。

Try running this command from shell script, result can be used to do further application installation. 尝试从shell脚本运行此命令,结果可用于进一步安装应用程序。

if [ `java -version | grep -q "java version"` ]; then
  echo "Java installed"
fi

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

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