0

i have problem running JAVA program from CLI:

Java from CLI

As you can see, i run javac Main.java to get Main.class file. And when trying to execute java Main, java can't find Main class. There is my class in Eclipse:

enter image description here

What am i doing wrong?

0

3 Answers 3

1

You should first compile your class then run the the compiled class and not the sources. So from command line:

d:
cd programos/xampp/htdocs/im/OpenCV/src/stitching
javac Main.java

The above command will tell the java compiler to compile the sources of the Main class and generate a .class in bytecode which can be passed to the java process to be run:

java Main
Sign up to request clarification or add additional context in comments.

Comments

0

You have to go one dir up cd .. and than java stitching.Main

3 Comments

Still nothing, "Error: Could not find or locate main class Main" running "java -cp Main.class Main"
@Justinas Sorry my fault. I have corrected my answer
@Justinas: the classpath (-cp) argument should contain the folders or JARs that contain the classes, not the classes themselves. From the src folder, try java -cp . stitching.Main.
0

Because you declared your Main class to be in package stitching, what you should need to do is actually navigate to the folder above the root package (in the bin directory), then execute java stitching/Main

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.