无法在jdk1.7中编译和运行HelloWorld [英] Unable to compile and run HelloWorld in jdk1.7

查看:119
本文介绍了无法在jdk1.7中编译和运行HelloWorld的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在e:\上安装了jdk1.7.我在c:\的计算机中已经有jdk1.61.5.

I have installed jdk1.7 at my e:\. i have already jdk1.6 and 1.5 in my machine at 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:\

在此处输入代码

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和类路径出现在JDK 7之前.我相信这是问题所在.

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

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

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.

或者,仅删除Java的旧版本.为什么需要它们?

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

这篇关于无法在jdk1.7中编译和运行HelloWorld的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆