0

There is a directory called Programs. Inside that I have my java program called Main.java. I compiled it using this command,

javac Main.java

It compiled properly without any errors.

My program takes in three command line arguments. So to run my program in a Linux machine I use this command when I am present inside the Programs directory,

java Main arg1 arg2 arg3

That works well.

However if I am in some other directory and try to run this program like,

java /home/Blake/Main arg1 arg2 arg3

I am getting an error like this - Error: Could not find or load main class

I tried this command too, but I get same error message:

java -cp /home/Blake/Main arg1 arg2 arg3

What am I doing wrong here?

Any input is well appreciated. Thanks!

Kemat Rochi
  • 932
  • 3
  • 21
  • 35
  • 1
    You want to start by reading basic tutorials on packages and class path setup. This is a super basic thing documented in countless places. – GhostCat Jun 20 '17 at 02:27

1 Answers1

4

You nearly did it correctly:

java -cp /home/Blake Main arg1 arg2 arg3

see How can I compile and run a Java class in a different directory?

N4zroth
  • 1,334
  • 2
  • 10
  • 25