I'm Having some trouble with executing java files in my terminal (using Macbook). My original program creates text files in specific folders and opens said text file, but I will demonstrate using a simple java program, Hello.java.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello there!");
}
}
This is located in a folder, named Projects. I can run it in my IDE, and I can compile it. So now i have Hello.java and Hello.class located inside the folder.
When I try to run it with
sebastian@Sebastians-Air Projects % java Hello
I get this error message:
Error: Could not find or load main class Hello
Caused by: java.lang.ClassNotFoundException: Hello
Here's some additoinal info:
sebastian@Sebastians-Air Projects % javac -version
javac 14
sebastian@Sebastians-Air Projects % java -version
openjdk version "14" 2020-03-17
OpenJDK Runtime Environment (build 14+36-1461)
OpenJDK 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)
The java file is not in a package and the Projects folder (which has the Hello files) is located at the Desktop.
I have tried javac -cp . Hello.java
and then calling java -cp . Hello
Any help is greatly appreciated!