如何在不更改类路径和路径的情况下在 1.6 或更旧版本中编译 java?我们只需要使用命令行执行即可

How to compile java in 1.6 or older version without changing the classpath and path? We only need to use command line to execute the same

如何在不更改类路径和路径的情况下在 1.6 或更旧版本中编译 java?我们只需要使用命令行来执行相同的。 喜欢:

javac var -1.6 Hello.java
java Hello

要编译代码和目标 Java 1.6,您可以指定 targetsource 编译器选项。像,

javac -target 1.6 -source 1.6 Hello.java

javac -help说明,

-source <release>    Provide source compatibility with specified release
-target <release>    Generate class files for specific VM version

在 1.6 或更旧版本中编译 java 而不更改类路径和路径

  javac -source 1.6 Test.java

这将帮助您使用

来理解
javac -help

-source <release>    Provide source compatibility with specified release