This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Running a Java Program from Command Prompt

 
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.
 
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%;.
 
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.
 
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
 
    Bookmark Topic Watch Topic
  • New Topic