![]() |
Setting Up Eclipse with Java 1.6 on Windows |
|
Step 1 - Download Java Step 2 - Install Java Step 3 - Set the PATH Step 4 - Set the CLASSPATH Step 5 - Test the Java installation Step 6 - Download and install Eclipse Step 7 - Test the Eclipse installation Step 1 Download Java 1.6 package for Windows. Click the Download button alongside the label JDK 6 Update 2 (or similar). On that page, accept the license agreement near the top of the page and download either the online or offline Windows Platform installation file. The offline option is a big file (c. 66MB) which includes all of the Java language and can be used to install even when an internet connection is not available. The online option is a small file (c. 0.4MB) that when run downloads Java over an internet connection as installation proceeds. It is recommended that you save the installer file to the Desktop so that it can be found easily. Step 2 Install the Java 1.6 package. a. Double-click the file that you just downloaded. The name should be something similar to jdk-6u2-windows-i586-p.exe or, if you chose the online installation option, jdk-6u2-windows-i586-p-iftw.exe b. Accept the License Agreement. c. Accept all the default choices. In other words, just keep clicking "Next". d. Wait for the installation to complete. Step 3 Update the PATH environment variable. (The following is adapted from Sun's Installation Notes for JDK 1.6 Microsoft Windows) You can run the JDK without setting the PATH variable, or you can optionally set it as a convenience. To save yourself a lot of careful typing, it is highly recommended that you set the path variable. Set the PATH variable if you want to be
able to conveniently run the JDK executables ( C:> "\Program Files\Java\jdk1.6.0_<version>\bin\javac" MyClass.javaIt'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:
Microsoft Windows 98 - To set the PATH permanently, open the AUTOEXEC.BAT file and add or change the PATH statement as follows:
Microsoft Windows ME - To set the PATH permanently: From the start menu, choose programs, accessories, system tools, and system information. This brings up a window titled "Microsoft Help and Support". From here, choose the tools menu, then select the system configuration utility. Click the environment tab, select PATH and press the edit button. Now add the JDK to your path as described in step b above. After you've added the location of the JDK to your PATH, save the changes and reboot your machine when prompted. Step 4 Set the CLASSPATH environment variable. The CLASSPATH variable tells Java where to look for *.class bytecode files. Bytecode is created when you compile your *.java files. Set the CLASSPATH 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 CLASSPATH:
Microsoft Windows 98 - To set the CLASSPATH permanently, open the AUTOEXEC.BAT file and add or change the CLASSPATH statement as follows:
Microsoft Windows ME - To set the CLASSPATH permanently: From the start menu, choose programs, accessories, system tools, and system information. This brings up a window titled "Microsoft Help and Support". From here, choose the tools menu, then select the system configuration utility. Click the environment tab, select CLASSPATH and press the edit button. Now add '.' and '..' to your path as described in step b above. Then save the changes and reboot your machine when prompted. Step 5 Test your Java installation. a. Open a command window and create a test directory.
b. Open a text editor and create a small Java program. Open WordPad or NotePad (in XP these can be found at Start >> All Programs >> Accessories) and copy in the following simple program: public class MyTestApplication { c. Save the program in the test directory. In the text editor menu, choose File >> Save. Then in the File Name field near the bottom of the dialog box, type the following exactly - C:\test\MyTestApplication.java
and click Save.d. Confirm the save. In your command window, type dir. You should see something similar to - C:\test>dir
Volume in drive C has no label. Volume Serial Number is 3C4D-5998 Directory of C:\test 29/01/2006 08:20 PM <DIR> . 29/01/2006 08:20 PM <DIR> .. 29/01/2006 08:20 PM 129 MyTestApplication.java 1 File(s) 129 bytes 2 Dir(s) 59,076,812,800 bytes free C:\test> e. Compile the program. Type javac MyTestApplication.java and press Enter. You should see - C:\test>javac MyTestApplication.java Problem 1
If instead you get the following message -
C:\test>javac MyTestApplication.java then Java has not been correctly installed. Perform the following tests :
1) Check that Java has been correctly downloaded and installed. In particular, look for the directory C:\Program Files\Java\jdk1.6.0_<version>\bin. If you cannot find a Java folder in the Program Files folder, then go back to Step 1 now. 2) Check that the PATH variable has been set correctly. Type echo %path%. You should see something similar to - C:\test>echo %path% If you do not see an entry anywhere in your PATH similar to the one above in bold, then go back to Step 3 now.
Problem 2
If instead you get the following message - C:\test>javac MyTestApplication.java 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%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. f. Confirm the compilation. Type dir. You should see something similar to - C:\test>dirIf compilation was successful, a *.class file should be present as shown. g. Run the program. Type java MyTestApplication to run the program. You should see - C:\test>java MyTestApplicationThere is one common problem at this step. Problem
If you get the following message - C:\>java MyTestApplication then either your class file is not in the test folder (type dir at the command line to make sure), or you are in the wrong directory as in this example, where the java command has been typed in C: rather than C:\test. Go back to Step 5b above and make sure that you have performed all steps correctly.
Step 6 Download and install Eclipse.
(Note: you need to configure Eclipse to use Java 1.6 or it will use an older Java version by default)
Step 7 Test the Eclipse installation. Create a new Java project with a class and run it.
public class MyTestApplication { 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. "Hello World!" should appear in the console output. Please report any errors found on this page to mike@cs.ubc.ca |
||
©University of British Columbia | Last updated:
August 31, 2007 17:21 |