D
D
Daniil Buzyurov2022-01-28 14:55:00
Java
Daniil Buzyurov, 2022-01-28 14:55:00

Java. I can't run the program through the command line. What to do?

I use Intellej IDEA.
In the IDE itself, everything works, but when I do the same actions myself through the command line, it gives an error "could not find or load main class";
61f3d839cbc39886126910.jpeg
and with another program
61f3d87008222846091542.jpeg
As a result, I tried to transfer the file, rename, compile again with a new name, did it through Intellej and through Power Shell and through win + R - cmd and everything does not work exactly ...
I indicated the package, tried to run it with him and without him.
Environment variable settings
61f3d91837944678288903.jpeg
Added and removed \bin folder to JAVA_HOME directory
I don't know what to do....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2022-01-28
@buzujava

Because you are trying to run the file homework.lesson8.HelloWorld while in the directory with the file. java logically tries to find the ./homework/lesson8/HelloWorld.class file and breaks off and tells you about it.
java HelloWorld doesn't work either. java finds the HelloWorld.class file inside which says that it belongs to the homework.lesson8 package, that is, this is not the file that the user wants to run.
Do cd ../.. (change to src directory) and run java homework.lesson8.HelloWorld - will work
But in general mixing source code (*.java) and compiled files (*.class) in the same directories is a very bad idea. Note that IDEA, when compiling files, puts them in the out folder. You can go there and run your program from that folder (then you don't need to call javac separately). Or specify in the javac options where you want to put the compiled files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question