If your program file has package statement then all these classes defined inside the file must be stored into package name folder.
Example in above post:
>javac AccountBalance.java -d .
statement creates a folder MyPack in current directory (. with command line) and both Balance.class and AccountBalance.class files are placed into MyPack folder.
Run - JVM launch AccountBalance class from file system folder MyPack.
>java MyPack.AccountBalance
If you want to store compiled classes in another folder other that current directory.
>java AccountBalance.java -d c:\test
Thanks for the reply. I am assuming that the last sentence in your post should have "javac" instead of "java". Please correct me if I am wrong.
I did that. Actually to be exact I did the following thing:
c:\jtemp\mypack>javac AccountBalance.java -d c:\jtemp\adat
As expected a folder "MyPack" was created inside the "adat folder.
For confirmation this is the address of the folder I am talking about
:
c:\jtemp\adat\mypack>
Also, as per expectations, it has the 2 class files.
Now this is where my usual problem begins. The problem I can't get around no matter what I try; the problem who's answer is what I am seeking on the internet.
How should I execute these class files? Every attempt I make yields the result "NoClassDefFoundError".
Please help. These are the ways I have attempted to execute the classes:
1. c:\jtemp\adat\mypack>java MyPack.AccountBalance
2. c:\jtemp\adat\mypack>java .AccountBalance
3. c:\jtemp\adat>java MyPack.AccountBalance
4. c:\jtemp\adat>java AccountBalance
All result in the same error. It is not the compilation, or the place where the class files get stored is the issue. The issue is how do I run the class files? I know only one way - and I must thank you (adatapost) for that respite - but that method is too restricted. This only method is what I have given in my first post. But when I change the location where the classes are finally compiled, I can't run them.
Please help!
Regards,
-sgsawant