简体   繁体   English

javac -version显示什么?

[英]What does javac -version show?

Even the official documentation of javac 甚至是javac官方文档
says nothing about the -version option. 对-version选项一无所知。

Javac -version tells you about the JDK version. Javac -version告诉你JDK版本。 That is, it gives the information of Compiler. 也就是说,它提供了编译器的信息。

Official page does mention about it: 官方页面确实提到了它:

http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html

Why you cannot find on the page is, -version is not available for javac until Java 6 I believe (I am sure it is not available in 1.4 and before). 为什么你在页面上找不到, -version直到Java 6才能用于javac我相信(我相信它在1.4之前和之前都没有)。 That's why it is not showing on your page, which is javac ref page for Java 1.5. 这就是为什么它没有显示在你的页面上,这是Java 1.5的javac ref页面。 However, go to java command reference page of Java 1.5 and you should be able to find the -version switch. 但是,转到Java 1.5的java命令参考页面,您应该能够找到-version开关。

This command outputs your java compiler's version. 此命令输出您的java编译器的版本。 In mine case it shows 1.6.0 在我的情况下它显示1.6.0

You are looking at the official documentation for an OBSOLETE version of javac Java 5. The -version option is documented in the javac manual entry for Java 6 and Java 7. 您正在寻找的一个过时版本的官方文档javac的Java 5. -version选项在文件javac的Java 6和Java 7手工录入。

And in response to your question about what -version actually shows (for javac and java ) the best answer is "unspecified" or "it depends on what version / platform you are using". 并且回答你关于什么-version实际显示的问题(对于javacjava ),最好的答案是“未指定”或“它取决于你正在使用的版本/平台”。 In practice, your best bet is to just try it for yourself. 在实践中,你最好的选择就是亲自尝试。


If your reason for asking is that you want to extract some useful information about the Java platform from the version strings ... I recently tried searching for a web page that listed the version strings for the java command, and came up empty. 如果您要问的原因是您想从版本字符串中提取有关Java平台的一些有用信息...我最近尝试搜索列出了java命令的版本字符串的网页,并且显示为空。 A better approach would probably be to write a tiny Java application to print out the relevant properties from the System properties object. 一种更好的方法可能是编写一个小型Java应用程序来打印System属性对象中的相关属性。 The javadoc for System lists a number of properties that are standardised. System的javadoc列出了许多标准化的属性。

Just to expand, both display the same; 只是为了扩展,两者都显示相同; the version of Java that the tools are part of. 工具所属的Java版本。

You can ASSUME that what one reports, the other will automatically also report and so it is overkill to have the option in both. 您可以确定报告的内容,另一个会自动报告,因此在两者中都有选项是过度的。 Until the moment you encounter a machine where there are multiple versions of Java installed and you can compile something yet you can't run it. 直到您遇到安装了多个Java版本的计算机并且您可以编译某些内容但您无法运行它的那一刻。 Displaying the versions of javac and java can then quickly tell you that the setup of the machine is messed up enough that different versions of Java are being used to compile and run. 显示javac和java的版本然后可以快速告诉您机器的设置已经搞砸了,不同版本的Java被用于编译和运行。 And then you thank the designers for adding it in. 然后你感谢设计师添加它。

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

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