我正在使用 javac 1.6 编译一些 java 代码。
多次catch异常会产生大量错误。这在 java 7 中没有问题。
从命令行运行时,我想使用 javac 1.7 而不是当前使用的 javac 1.6。我怎样才能实现它?
(我的电脑上安装了 JDK 7)
最佳答案
因为您没有提及您的平台,所以我假设您使用的是 Windows 7
。以下是有关如何设置路径并通过扩展更改路径的说明:
Windows 7:
From the desktop, right click the Computer icon.
Choose Properties from the context menu.
Click the Advanced system settings link.
Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
那么,您需要为 PATH
输入什么值?
对我来说,它是:C:/Program Files/Java/jdk1.7.0_21/bin
一切顺利。
来源:http://docs.oracle.com/javase/tutorial/essential/environment/paths.html
Right click your project choose properties. Select Java Build Path -> Libraries, select JRE System Library, click Edit and choose whichever JRE or JDK you like. You can also add from this screen a new JRE or JDK.
来源:http://www.javavids.com/video/how-to-change-jre--jdk-in-eclipse-project.html
如果您使用 Netbeans 该怎么办?
Step One
In your Netbeans home directory (for example, C:\Program Files\NetBeans 7.0.1), open up the netbeans.conf in the etc directory (C:\Program Files\NetBeans 7.0.1\etc\netbeans.conf). Step Two
Theres a property called netbeans_jdkhome. Change the value to match the JDK you want Netbeans to use (for example, C:\Program Files\Java\jdk1.6.0_25). Step Three
Save your changes Step Four
Restart Netbeans
来源:http://davidwburns.wordpress.com/2012/02/15/how-do-i-change-the-jdk-home-for-netbeans/
我知道OP正在使用命令行,但为了完整起见,我添加了额外的信息
关于java - 如何使用 javac 1.7 而不是 1.6?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19409632/