Setting Up Eclipse With Java 1
Setting Up Eclipse With Java 1
Setting Up Eclipse With Java 1
6 on Windows
http://www.ugrad.cs.ubc.ca/~cs211/tutorials/Eclipse/Eclipse_Java_Wi...
1
2
3
4
5
6
7
Download Java
Install Java
Set the PATH
Set the CLASSPATH
Test the Java installation
Download and install Eclipse
Test the Eclipse installation
Step 1
It's useful to set the PATH permanently so it will persist after rebooting.
To set the PATH permanently, add the full path of the jdk1.6.0_<version>\bin directory to the PATH variable.
Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_<version>\bin, where
<version> is a two-digit number. Set the PATH as follows, according to whether you are on Microsoft Windows NT,
XP, 98, 2000, or ME.
Microsoft Windows NT, 2000, and XP - To set the PATH permanently:
a. Choose Start, Settings, Control Panel, and double-click System. On Microsoft Windows NT, select the
Environment tab; on Microsoft Windows XP and 2000 select the Advanced tab and then Environment Variables.
Look for "Path" in the User Variables and System Variables. If you're not sure where to add the path, add it to
the right end of the "Path" in the User Variables. A typical value for PATH is:
C:\Program Files\Java\jdk1.6.0_<version>\bin
Where <version> is the latest version number. For example, if you downloaded jdk1.6.0_02, then the value
to add to the path is:
C:\Program Files\Java\jdk1.6.0_02\bin
Capitalization doesn't matter. Click "Set", "OK"
or "Apply".
The PATH can be a series of directories separated by semi-colons (;). Microsoft Windows looks for programs in
the PATH directories in order, from left to right. You should only have one bin directory for a JDK in the path at
1 of 6
1/30/2015 12:46 AM
http://www.ugrad.cs.ubc.ca/~cs211/tutorials/Eclipse/Eclipse_Java_Wi...
a time (those following the first are ignored), so if one is already present, you can update it to
jdk1.6.0_<version>\bin.
b. The new path takes effect in each new Command Prompt window you open after setting the PATH variable.
Microsoft Windows 98 - To set the PATH permanently, open the AUTOEXEC.BAT file and add or change the PATH
statement as follows:
a. Start the system editor. Choose "Start", "Run" and enter sysedit, then click OK. The system editor starts up
with several windows showing. Go to the window that is displaying AUTOEXEC.BAT
b. Look for the PATH statement. (If you don't have one, add one.) If you're not sure where to add the path, add it
to the right end of the PATH. For example, in the following PATH statement, we have added the bin directory at
the right end:
PATH C:\WINDOWS;C:\WINDOWS\COMMAND;"C:\PROGRAM FILES\JAVA\JDK1.6.0_<version>\BIN"
Capitalization doesn't matter. The PATH can be a series of directories separated by semi-colons (;). Microsoft
Windows searches for programs in the PATH directories in order, from left to right. You should only have one
bin directory for a JDK in the path at a time (those following the first are ignored), so if one is already present,
you can update it to jdk1.6.0_<version>.
c. To make the path take effect in the current Command Prompt window, execute the following:
C:> c:\autoexec.bat
To find out the current value of your PATH, to see if it took effect, at the command prompt, type:
C:> path
b. The new classpath takes effect in each new Command Prompt window you open after setting the CLASSPATH
variable.
Microsoft Windows 98 - To set the CLASSPATH permanently, open the AUTOEXEC.BAT file and add or change
the CLASSPATH statement as follows:
a. Start the system editor. Choose "Start", "Run" and enter sysedit, then click OK. The system editor starts up
2 of 6
1/30/2015 12:46 AM
http://www.ugrad.cs.ubc.ca/~cs211/tutorials/Eclipse/Eclipse_Java_Wi...
c. To make the classpath take effect in the current Command Prompt window, execute the following:
C:> c:\autoexec.bat
To find out the current value of your CLASSPATH, to see if it took effect, at the command prompt, type:
C:> classpath
Step 5
3 of 6
1/30/2015 12:46 AM
http://www.ugrad.cs.ubc.ca/~cs211/tutorials/Eclipse/Eclipse_Java_Wi...
Directory of C:\test
29/01/2006
29/01/2006
29/01/2006
08:20 PM
<DIR>
.
08:20 PM
<DIR>
..
08:20 PM
129 MyTestApplication.java
1 File(s)
129 bytes
2 Dir(s) 59,076,812,800 bytes free
C:\test>
Problem 2
If instead you get the following message C:\test>javac MyTestApplication.java
error: cannot read: MyTestApplication.java
1 error
C:\test>
then either the CLASSPATH variable is not set or your file is not in the test folder. Perform the following tests:
1) Check that the CLASSPATH variable has been set correctly. Type echo %classpath%. You should see
something similar to C:\test>echo %classpath%
.;..;C:\someFolder\someClasses.jar
C:\test>
Note that the classpath may have been automatically updated to contain the location of various class files, and
therefore may be longer than the example above. Just make sure that it contains a '.' with a ';' to separate it
from other entries. Go back to Step 4 above to edit the classpath.
2) Make sure you are in the test folder. If you are not, then use the cd command to navigate to the test
folder. Once you are in the test folder, type dir at the command line to examine its contents. If you do not
see an entry for MyTestApplication.java then Go back to Step 5b above.
4 of 6
1/30/2015 12:46 AM
http://www.ugrad.cs.ubc.ca/~cs211/tutorials/Eclipse/Eclipse_Java_Wi...
08:28 PM
<DIR>
.
08:28 PM
<DIR>
..
08:28 PM
440 MyTestApplication.class
08:20 PM
129 MyTestApplication.java
2 File(s)
569 bytes
2 Dir(s) 59,076,796,416 bytes free
C:\test>
If compilation was successful, a *.class file should be present as shown.
Step 6
1.
2.
3.
4.
5.
6.
Now set up Eclipse to use the latest version of Java for compiling and running your Java programs.
(Note: you need to configure Eclipse to use Java 1.6 or it will use an older Java version by default)
1. Set the default installed JRE to Java 1.6 (this tells Eclipse which libraries to use):
Open the Eclipse Preferences Pane (Window -> Preferences) and go to the Java >> Installed JREs
subpane.
Check the JRE 1.6.0_<version> as the default (where <version> is a two digit number representing the
version number that you downloaded and installed)
Click OK to save the settings.
2. Set the Java compiler to Java 1.6 (this tells Eclipse which compiler to use):
In Eclipse Preferences Pane go to Java >> Compiler >> Compliance Level
Select "6.0".
Click OK to save the settings.
Eclipse should then be set up properly to compile and run Java 1.6 programs.
Step 7
5 of 6
1/30/2015 12:46 AM
http://www.ugrad.cs.ubc.ca/~cs211/tutorials/Eclipse/Eclipse_Java_Wi...
In the Java Perspective, right-click in Eclipse's Package Explorer window and select New >> Project....
Select Java Project and Next.
Name the project whatever you like (e.g. 'test'). For now the other options do not matter; just click on Finish.
In the Package Explorer window, right-click on the test package and select New >> Class.
Name the class MyTestApplication. For now the other options do not matter; just click on Finish.
Delete everything in the editor that appears. Copy the following into the editor:
public class MyTestApplication {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
7. In the Eclipse menu bar, select File >> Save. If everything is working properly this program should compile
automatically without errors.
8 Run the program by right-clicking on the MyTextApplication class in the package manager, then select Run As
>> Java Application.
6 of 6
1/30/2015 12:46 AM