Based on java documentation, I've set up my project as such:
Source files are in C:\...\sources\com\myname\tictactoe\
And my class files are in C:\...\classes\com\myname\tictactoe\
When I try to run a class (Main.java
) in that directory (on powershell) by running "java Main
", I get "Error: Could not find or load main class Main Caused by: java.lang.ClassNotFoundException: Main
". All my files start with "package com.myname.tictactoe;
", and from what I understand that's how they're supposed to be. What am I doing wrong?
Asked
Active
Viewed 45 times
0

Noam Bechhofer
- 51
- 7
-
Main.java is the source file, not the classfile – Michael May 24 '22 at 17:05
-
2what happens when you run `java -cp . com.myname.tictactoe.Main` in the `classes` folder? – f1sh May 24 '22 at 17:05
-
have you set the classpath somewhere? If not then check this out .. https://stackoverflow.com/questions/2396493/what-is-a-classpath-and-how-do-i-set-it – Lalit Mehra May 24 '22 at 17:06
2 Answers
2
Your java class has a package name so you will not be able to run just java Main. You will need to run java com.myname.tictactoe.Main.

M. Rizzo
- 1,611
- 12
- 24
0
Change directory to C:\...\classes
then run
java -cp . com/myname/tictactoe/Main

Eskandar Abedini
- 2,090
- 2
- 13
-
Worked! Ty. Just had to insert an extra com/ before the myname directory :) – Noam Bechhofer May 24 '22 at 18:20
-