开发者

command prompt java path error

C:\>set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_02

C:\>set path=./;C:\Program Files\Java\jdk1.6.0_02\bin;%path%

C:\>set classpath=%classpath%;

C:\>javac
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  ... (rest stripped)


C:\>javac sa1.java

C:\>java sa1
Exception in thread "main" java.lang.NoClassDefFoundError: sa1

C:\>

I have installed java in c drive I开发者_JS百科 have set path properly but prg is not running.

Please help me.


Your classpath does not contain the execution-directory C:>set classpath=%classpath%;

try C:>set classpath=.;%classpath%;


C:>set path=./;C:\Program Files\Java\jdk1.6.0_02\bin;%path%

Think the problem is with the ./ Take away the forward slash

C:>set path=.;C:\Program Files\Java\jdk1.6.0_02\bin;%path%

If your classpath does not have the current directory . Put that in.


It looks like your java source file compiles (with the current classpath settings) but won't execute. Do you need additional jars to execute the application? If not, please delete the CLASSPATH variable. If there is no classpath set through this variable or the -cp parameter, it defaults to the working directory (.) which is OK in most cases.

Double check the package definition of your sa1 class, if it is located in the correct directory and if you're in the correct working directory. Just an example:

 package com.example;
 public class Test {}

The compiled class file needs to be stored in ./com/example/Test.class. Then you can execute the application (imagine it has a main method) with java com.example.Test

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜