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!
Answer
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?
No comments:
Post a Comment