rasilvap
rasilvap

Reputation: 2159

java -cp Error: Could not find or load main class (java.lang.ClassNotFoundException)

I'm basically following the next tutorial: https://picocli.info/#_running_the_application

And I'm trying to run my Application with the next command:

java -cp "picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar" src/main/java/TestPicoCli.java --algorithm SHA-1 hello.txt

I'm located in a directory where I have the 2 jars picocli and bashTool, but I'm getting the next error message:

Error: Could not find or load main class src.main.java.TestPr.java
Caused by: java.lang.ClassNotFoundException: src.main.java.TestPr.java

This is how y directory looks like:

enter image description here

Any ideas?

Upvotes: -1

Views: 929

Answers (2)

skyrex23
skyrex23

Reputation: 106

The command java can execute a compiled (bytecode) Java file .class You are trying to execute a source file .java and it is not correct.

First, you need to find the TestPicoCli.class file. It could be generated by your IDE and is possibly in target/classes

Then, if you are in the folder that contains the TestPicoCli.class, you have to run:

java -cp "<path_to_your_jar>/picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar" TestPicoCli // Without .class

Or if you are in the folder that contains the .jar, you should run:

java -cp "picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar;<path_to_class_file>" TestPicoCli

Note: If you are on Linux, replace ; with :

Upvotes: 1

Abhishek Bansal
Abhishek Bansal

Reputation: 58

Try java -cp "picocli-4.6.3.jar:bashTool-1.0-SNAPSHOT.jar" TestPicoCli --algorithm SHA-1 hello.txt

Upvotes: 1

Related Questions