Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running a Java Program from Command Prompt

 
Asuthosh Borikar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am a beginner to java and I am facing this problem. I have a program zzz, which has a package statement: com.xxx.yyy.
My source file is in c:\com\xxx\yyy folder. I am able to compile the program with the command javac -d c:\ zzz.java and the .class file is placed in c:\com\xxx\yyy, but I get a NoClassDefFoundError when I try : java zzz, from c:\com\xxx\yyy. If I give the fully qualified name java com.xxx.yyy.zzz from c:\, it executes successfully. Is it a must that I give the fully qualified name each time I try to execute a program in a package? If yes, why do we have to include the root directory of the package in the CLASSPATH? Only so that the compiler can find the classes when they are imported in other classes? Please help me.
 
shree vijay
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you can solve the problem by adding the current directory to the classpath .
classpath = %classpath%;.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The current directory is always in the default class path. When u dont specify the path of your class file it tries to see if it is there in the current directory or in the class path.
As u have compiled giving the fully qualified name, i suggest u go into the folder where ur programs are and compile/run it, or put the working folder in your class path to compile or run from anywhere.
 
Srinivasa Gajula
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Asuthosh,
A easy way is to create a batch file that sets up path for all your class files.
Add the following to batch file(say setpath.bat)
SET CLASSPATH=.;%CLASSPATH%;c:\com\xxx\yyy
run this batch file in a dos session and then run your java program
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic