This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
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
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Running a Java Program from Command Prompt