在jdk1.7中无法编译运行HelloWorld

发布于 2024-11-27 13:32:02 字数 1818 浏览 0 评论 0原文

我已在我的 e:\ 处安装了 jdk1.7。我的机器中已经有 jdk1.61.5,位于 c:\ 位置。

环境可用,

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

在 cmd 提示符下,

E:\>java -version
java version “1.7.0″
Java(TM) SE Runtime Environment (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

无法编译位于 e:\Hello7.java

在此处输入代码

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");   
      }  
   }
}

否 Tom,在尝试编译时仍然出现错误。请找到以下状态。

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

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 Environment (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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扭转时空 2024-12-04 13:32:02

路径和类路径中的 JDK 6 出现在 JDK 7 之前。我相信这就是问题所在。

首先尝试从类路径和路径环境变量中删除 JDK 6,然后重试。如果它有效,您可能必须创建为 java 7 设置环境的 bat 文件并在使用 java 7 之前运行它。

或者只需删除旧版本的 java 即可。为什么需要它们?

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?

哀由 2024-12-04 13:32:02

在您的类路径中,您在 e:\jdk1.7\lib;.; 处有 java 7

请注意jdk1.7

在您的路径中,当您指定环境变量时,e:\jdk1.7\bin 处有 java 7,但随后您将其设置为 e:\javasdk1.7\bin 行中:

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

注意 javasdk1.7< /强>。

由于 javac 正在运行,看来您设置的新路径必须是正确的。您的类路径应该与其匹配(正如其他人指出的那样,删除对 j​​ava 7 安装的引用):

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

进行更改,它应该能够找到丢失的类。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文