-
On Windows or Linux: In Eclipse's main menu, select Window→Preferences. On a Mac: In Eclipse's main menu, select Eclipse→Preferences.
As a result, Eclipse's Preferences dialog appears.
-
In the tree on the left side of the Preferences dialog, expand the Java branch.
-
Within the Java branch, select the Installed JREs sub-branch.
-
Look at the list of Java versions (Installed JREs) in the main body of the Preferences dialog.
In the list, each version of Java has a check box. Eclipse uses the version whose box is checked. If the checked version isn't your preferred version (for example, if the checked version isn't version 8 or higher), you can make some changes.
-
If your preferred version of Java appears in the Installed JREs list, put a check mark in that version's check box.
-
If your preferred version of Java doesn't appear in the Installed JREs list, click the Add button.
When you click the Add button, a JRE Type dialog appears.
-
In the JRE Type dialog, double-click Standard VM.
As a result, a JRE Definition dialog appears. What you do next depends on a few different things.
-
Fill in the dialog's JRE Home field.
How you do this depends on your operating system.
-
On Windows, browse to the directory in which you've installed your preferred Java version. On your Windows computers, that directory is either C:Program FilesJavajre8, C:Program FilesJavajdk1.8.0, C:Program Files (x86)Javajre8, or something of that sort.
-
On a Mac, use the Finder to browse to the directory in which you've installed your preferred Java version. Type the name of the directory in the dialog's JRE Home field.
My Mac has one Java directory named /System/Library/Java/Java Virtual Machines/1.6.0.jdk/Contents/Home and another Java directory named /Library/Java/JavaVirtualMachines/jdk 1.8.0.jdk/Contents/Home. (The first is for Apple's old version of Java; the second is for Oracle's new Java version.) You might also find Oracle's Java in the /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home directory.
Directories like /System and /Library don't normally appear in the Finder window. To browse to one of these directories (to the /Library directory, for example), choose Go→Go to Folder in the Finder's menu bar. In the resulting dialog, type /Library and then press Go.As you navigate to the directory containing your preferred Java version, you may encounter a JDK 1.8.0.jdk icon or some other item whose extension is .jdk. To see the contents of this item, control-click the item's icon and then select Show Package Contents.
-
On Linux, browse to the directory in which you've installed your preferred Java version. When in doubt, search for a directory whose name starts with jre or jdk.
You might have one more thing to do back in the JRE Definition dialog.
-
-
Look at the JRE Definition dialog's JRE Name field; if Eclipse hasn't filled in a name automatically, type a name (almost any text) in the JRE Name field.
-
Dismiss the JRE Definition dialog by clicking Finish.
Eclipse's Preferences dialog returns to the foreground. The box's Installed JREs list contains your newly added version of Java.
-
Put a check mark in the check box next to your newly added version of Java.
You’re almost done. (You have a few more steps to follow.)
-
Within the Java branch on the left side of the Preferences dialog, select the Compiler sub-branch.
In the main body of the Preferences dialog, you see a Compiler Compliance Level drop-down list.
-
In the Compiler Compliance Level drop-down list, select a number that matches your preferred Java version.
For Java 7, you select compliance level 1.7. For Java 8, you select compliance level 1.8.
-
Whew! Click the Preferences dialog's OK button to return to the Eclipse workbench.
How to Configure Java in Eclipse
|
| Updated:
2021-11-23 18:43:47
| From The Book:
No items found.
Eclipse normally looks on your computer for Java installations and selects an installed version of Java to use for running your Java programs. Your computer may have more than one version of Java, so you may want to double-check Eclipse's choice of the Java version. The following steps show you how: