Finnegan Finnegan - 3 years ago 227
Linux Question

Could not find or load main class - for any program

I'm having a problem where the 'java' command - no matter what I am trying to run, says that it 'Could not find or load main class'.

Everything is fine when compiling with javac, .class files are created. So when I run:



public class HelloWorld{
public static void main(String[] args){
System.out.println("Hello World");

everything compiles fine, a HelloWorld.class file is created along side the file. However when I then go to run:

java HelloWorld

1) the most telling sign is that when I press tab to autofill 'HelloWorld' nothing comes up.

2) when I do run it, I get the 'Error: Could not find or load main class HelloWorld' despite it being in the same directory, not being part of a package, compiling fine with a .class file, the program having a main class.

For reference running Fedora 23 64bit, openjdk version "1.8.0_111"

Any help appreciated, this is doing my head in.

Answer Source

Try using java -cp . HelloWorld

Some good reading:

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