简体   繁体   English

如何分辨已安装的Java的差异-JDK或JRE

[英]How to tell the diffarences of installed java - JDK or JRE


When I execute java.exe -version 当我执行java.exe -version
Both JDK and JRE say: SE Runtime Environment JDK和JRE都说: SE运行时环境
Is there other way to distinguish JDK or JRE 还有其他方法可以区分JDK或JRE

C:\Program Files\Java\1.6.0_45\bin>java.exe -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

Simple enough... Try and: 足够简单...尝试并:

javac.exec -version

If you get a message telling the version, you have the JDK. 如果收到告诉版本的消息,则说明您拥有JDK。 If you have a message telling you that the command is not found, you have the JRE. 如果有消息告诉您找不到该命令,则说明您拥有JRE。

If you take a look at the folder structure where jdk / jre is installed you would see that in the jdk/bin folder there are quite a collection of binaries such as java, javac, javap etc. The JRE would include java but not javac, javap etc. I am assuming this is linux and you downloaded the compressed archive and extracted that. 如果您查看安装了jdk / jre的文件夹结构,您会发现在jdk / bin文件夹中有相当多的二进制文件集合,例如java,javac,javap等。JRE将包含Java但不包含javac, javap等。我假设这是linux,并且您下载了压缩归档文件并将其解压缩。

But this is not the only difference, the JDK is the development kit that includes the JRE as well. 但这不是唯一的区别,JDK是也包括JRE的开发套件。 If you are interested in running java programs then JRE would suffice but if there is development including compilation then the JDK is required. 如果您对运行Java程序感兴趣,那么JRE就足够了,但是如果有包括编译在内的开发,那么就需要JDK。 Please also see: What is the difference between JDK and JRE? 还请参见: JDK和JRE有什么区别?

The bin folder structure differences between JDK and JRE (for example): JDK和JRE之间的bin文件夹结构差异(例如):

For the JRE: 对于JRE:

$ ll jre/bin/
total 452K
lrwxrwxrwx. 1 ec2-user ec2-user    8 Nov 18 18:27 ControlPanel -> jcontrol
drwxr-xr-x. 5 ec2-user ec2-user 4.0K Sep 17 20:42 ..
drwxr-xr-x. 2 ec2-user ec2-user 4.0K Sep 17 20:42 .
-rwxr-xr-x. 1 ec2-user ec2-user 7.6K Sep 17 20:42 java
-rwxr-xr-x. 1 ec2-user ec2-user 130K Sep 17 20:42 javaws
-rwxr-xr-x. 1 ec2-user ec2-user 6.2K Sep 17 20:42 jcontrol
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jjs
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 keytool
-rwxr-xr-x. 1 ec2-user ec2-user 8.0K Sep 17 20:42 orbd
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 pack200
-rwxr-xr-x. 1 ec2-user ec2-user 7.9K Sep 17 20:42 policytool
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 rmid
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 rmiregistry
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 servertool
-rwxr-xr-x. 1 ec2-user ec2-user 8.0K Sep 17 20:42 tnameserv
-rwxr-xr-x. 1 ec2-user ec2-user 224K Sep 17 20:42 unpack200

For the JDK: 对于JDK:

$ ll jdk/bin/

total 780K
lrwxrwxrwx. 1 ec2-user ec2-user    8 Nov 18 18:27 ControlPanel -> jcontrol
drwxr-xr-x. 8 ec2-user ec2-user 4.0K Sep 17 20:44 ..
drwxr-xr-x. 2 ec2-user ec2-user 4.0K Sep 17 20:42 .
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 appletviewer
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 extcheck
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 idlj
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jar
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jarsigner
-rwxr-xr-x. 1 ec2-user ec2-user 7.6K Sep 17 20:42 java
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 javac
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 javadoc
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 javah
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 javap
-rwxr-xr-x. 1 ec2-user ec2-user 1.8K Sep 17 20:42 java-rmi.cgi
-rwxr-xr-x. 1 ec2-user ec2-user 130K Sep 17 20:42 javaws
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jcmd
-rwxr-xr-x. 1 ec2-user ec2-user 7.9K Sep 17 20:42 jconsole
-rwxr-xr-x. 1 ec2-user ec2-user 6.2K Sep 17 20:42 jcontrol
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jdb
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jdeps
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jhat
-rwxr-xr-x. 1 ec2-user ec2-user 8.0K Sep 17 20:42 jinfo
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jjs
-rwxr-xr-x. 1 ec2-user ec2-user 8.0K Sep 17 20:42 jmap
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jps
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jrunscript
-rwxr-xr-x. 1 ec2-user ec2-user 7.8K Sep 17 20:42 jsadebugd
-rwxr-xr-x. 1 ec2-user ec2-user 8.0K Sep 17 20:42 jstack

So if you type javac and it the command is not recognized then this implies that the JDK/bin is not on the PATH . 因此,如果您键入javac并且无法识别该命令,则表明JDK/bin不在PATH Simple as that. 就那么简单。 It does not mean that the JDK is not installed on that host - it could be - it is just that JRE/bin is in the PATH and JDK/bin is not. 这并不意味着未在该主机上安装JDK(可能的话),只是JRE/bin位于PATH中,而JDK/bin没有。

When I execute the following on my box without JDK in the path 当我在没有路径的JDK的盒子上执行以下命令时

javac Java语言

I get; 我懂了

The term 'javac' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At line:1 char:6
+ javac <<<<
    + CategoryInfo          : ObjectNotFound: (javac:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Since I have the runtime in my path when I do the following 由于执行以下操作时我的路径中有运行时

java -version Java版本

I get; 我懂了

java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

On my mac which has jdk on the path when I do javac 在我执行javac时在路径上具有jdk的mac上

$ javac
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
...

In summary I run javac to see if I have the JDK active or not. 总而言之,我运行javac来查看JDK是否处于活动状态。

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

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