views:

72

answers:

2

Hi Guys,

I am not very experience with java and this is driving me crazy. I wrote a java program "FileManagement" and I need to run it from the command line.

I can compile it from the command line with "javac FileManagement/*.java" which will create all the classes in that folder but when I try "java FileManagement.Main" it says "Exception in thread "main" java.lang.NoClassDefFoundError: FileManagement/Main"

The thing is that I have tried this same procedure in a remote computer and it is working fine. It is not working on mine.

Thanks for your time

Altober

+6  A: 

If your Main class is in a package called FileManagement, then try:

java -cp . FileManagement.Main

in the parent folder of the FileManagement folder.

If your Main class is not in a package (the default package) then cd to the FileManagement folder and try:

java -cp . Main

More info about the CLASSPATH and how the JRE find classes:

Bart Kiers
Working!!!! Thanks a Lot. Problem solved
Altober
@Altober, good to hear that. I encourage you to read a bit about the classpath so you know why it didn't work.
Bart Kiers
cool thanks for your time
Altober
You should accept this answer if its the correct one.
TheLQ
+2  A: 

What is the package name of your class? If there is no package name, then most likely the solution is:

java -cp FileManagement Main
Thomas Mueller
Thanks for your time Bart K gave the same solution and It worked. Thanks again Thomas
Altober
If the main class was named "Main" (without package), and if the class was simply in the directory named "FileManagement". The same as cd FileManagement ; java cp . Main
Thomas Mueller
Ah, sorry, you added `FileManagement` to the classpath. I thought you tried to execute `FileManagement` and gave `Main` as a command line parameter.
Bart Kiers