简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM