Altober Altober - 1 year ago 64
Java Question

Running Java Program from Command Line Linux

I am not very experience with java and this is driving me crazy. I wrote a java program

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:

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.

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download