user2756339
user2756339

Reputation: 705

How to use javac 1.7 instead of 1.6?

I am compiling some java code using javac 1.6.

A large number of errors are generated for multi catch exceptions. This had no problem in java 7.

On running from command line I want to use javac 1.7 instead of javac 1.6 currently being used. How can I achieve it?

(JDK 7 is installed in my computer)

Upvotes: 0

Views: 3748

Answers (2)

An SO User
An SO User

Reputation: 25028

Because you have not mentioned your platform, I am going to assume you are using Windows 7. Here are the instructions on how to set the path and by extension change it:

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.  

So, what value for PATH do you need to enter?
For me, it is: C:/Program Files/Java/jdk1.7.0_21/bin
You are good to go.
Source: http://docs.oracle.com/javase/tutorial/essential/environment/paths.html


What if you are using an IDE like Eclipse ?

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.

Source: http://www.javavids.com/video/how-to-change-jre--jdk-in-eclipse-project.html



What if you are using 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

Source: http://davidwburns.wordpress.com/2012/02/15/how-do-i-change-the-jdk-home-for-netbeans/

I know the OP is using command line but for the sake of completeness, I have added extra information

Upvotes: 2

Rocky Pulley
Rocky Pulley

Reputation: 23321

Use the full path to it:

{path_to_jdk_7}\bin\javac 

Upvotes: 2

Related Questions