当我执行java.exe -version时
JDK和JRE都说: SE运行时环境
是否有其他方法可以区分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)
答案 0 :(得分:1)
足够简单......试试并且:
javac.exec -version
如果您收到告诉该版本的消息,那么您将拥有JDK。如果您有消息告诉您未找到该命令,则表明您已获得JRE。
答案 1 :(得分:1)
如果你看看安装了jdk / jre的文件夹结构,你会发现在jdk / bin文件夹中有很多二进制文件集合,比如java,javac,javap等.JRE会包含java但是不是javac,javap等我假设这是linux,你下载了压缩存档并提取了它。
但这不是唯一的区别,JDK也是包含JRE的开发工具包。如果您对运行java程序感兴趣,那么JRE就足够了,但如果有包括编译在内的开发,则需要JDK。另请参阅:What is the difference between JDK and JRE?
JDK和JRE之间的 bin 文件夹结构差异(例如):
对于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
对于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
因此,如果您键入javac
并且命令无法识别,则表示JDK/bin
不在PATH
上。就那么简单。这并不意味着JDK没有安装在该主机上 - 它可能是 - 只是JRE/bin
在PATH中而JDK/bin
不在。
答案 2 :(得分:1)
当我在路径
中没有JDK的盒子上执行以下操作时的javac
我明白了;
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
因为当我执行以下操作时,我的路径中有运行时
java -version
我明白了;
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)
在我的mac上,当我执行javac时,路径上有jdk
$ 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
...
总之,我运行javac
以查看我是否激活了JDK。