java - 如何使用 javac 1.7 而不是 1.6?

标签 java exception compilation jvm javac

我正在使用 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

<小时/> 如果您使用像 Eclipse 这样的 IDE 怎么办?

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/

相关文章:

Java:方法名称/签名解析是否静态完成(编译时)?

c++ - 在类中声明但未定义的方法

java - PrintWriter 创建空文件

java - 在 JUNG 图中拾取/移动/调整大小/删除注释

java - 如果消费者线程遇到异常,如何停止生产者线程

javascript通行证

compilation - 无法编译简单的 CUDA 示例

java - JNI : convert Primitive type to jobject Or SetObjectArrayElement of Object type after casting

单线程的 Java 线程池未按预期运行

c# - 停止/启动后 URI 的注册已经存在