开发者

Unable to compile and run HelloWorld in jdk1.7

开发者 https://www.devze.com 2023-03-25 02:48 出处:网络
I have installed jdk1.7 at my e:\\. i have already jdk1.6 and 1.5 in my machine at c:\\. Environment vairable,

I have installed jdk1.7 at my e:\. i have already jdk1.6 and 1.5 in my machine at c:\.

Environment vairable,

path=c:\jdk1.6\bin;e:\jdk1.7\bin;.;
classpath=c:\jdk1.6\lib;e:\jdk1.7\lib;.;

in cmd prompt,

E:\>java -version
java version “1.7.0″
Java(TM) SE Runtime E开发者_如何学Gonvironment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)

E:\>set path=e:\javasdk1.7\bin;.;

E:\>javac
Error: Could not find or load main class com.sun.tools.javac.Main

Not able to compile a Hello7.java which is at e:\

enter code here

import java.io.*;
class Hello7 {
   public static void main(String... args) {
      String color="red";
      switch (color) {   
      case "red":   
         System.out.println("Color is Red");   
         break;   
      case "green":   
         System.out.println("Color is Green");   
         break;   
      default:   
         System.out.println("Color not found");   
      }  
   }
}

No Tom, Still am getting error while trying to compile. Pleae find the below status.

E:\>dir j*
 Volume in drive E is Keane
  Volume Serial Number is BA91-B3F6

 Directory of E:\

 10/04/2010  05:25 PM    <DIR>          j2ee1.4.tutorials
 08/18/2011  02:52 PM    <DIR>          Jar Files
 08/02/2011  11:33 AM    <DIR>          javasdk1.7
 07/01/2011  04:39 PM    <DIR>          jboss
 10/04/2010  05:25 PM    <DIR>          jsf
 10/04/2010  05:25 PM    <DIR>          junit
           0 File(s)              0 bytes
           6 Dir(s)  33,454,637,056 bytes free

  E:\>set path=e:\javasdk1.7\bin;.;

  E:\>set classpath=e:\javasdk1.7\lib;.;

  E:\>javac
  Error: Could not find or load main class com.sun.tools.javac.Main


JDK 6 in you path and class path appears before JDK 7. I believe this is the problem.

Try first to remove JDK 6 from classpath and path environment variables and then try again. If it will work you probably have to create bat file that sets the environment for java 7 and run it before working with java 7.

Alternatively just remove older versions of java. Why do you need them?


In your classpath you have java 7 at e:\jdk1.7\lib;.;

Note the jdk1.7.

In you path you have java 7 at e:\jdk1.7\bin when you specify the environment vars, but then you set it to e:\javasdk1.7\bin in the line:

E:\>set path=e:\javasdk1.7\bin;.;

Note the javasdk1.7.

Since javac IS running, it seems the new PATH you set must be correct. Your classpath should match it (removing, as others have noted, the reference to your java 7 install):

classpath=e:\javasdk1.7\lib;.;

Make that change and it should be able to find the missing class.

0

精彩评论

暂无评论...
验证码 换一张
取 消