D
D
Dred Wolf2021-03-03 20:25:18
Java
Dred Wolf, 2021-03-03 20:25:18

How to compile and run Java from terminal if it gives this error?

1) There are directories:
- - - - application:
- - out - for binaries
- - src - for sources (App.java file is here)

Being in the application directory, I want to compile files from src to out:
javac -sourcepath ./src -d ./out App.java Error

:
error: file not found: App.java
Usage: javac
use --help for a list of possible options


out App.java
then everything will work and the binary will be in out.

2) If go to out directory and try to run App.class with:
java App
or
java -classpath ./App

Error:Could not find or load main class App
(PS code contains nested class)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-03-04
@DredWulf

javac -d out src/App.java
java -cp out App

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question