I know I can use mvn exec:java ...
to run my Maven project. But since I want to learn more about Java, I'm trying to run my project with the java
command. Here is my project structure:
pom.xml
src/
main/java/com/company/prod/
Obj.java
Main.java
target/
classes/com/company/prod/
Obj.class
Main.class
I'm trying to run Main by executing java -cp target/classes/com/company/prod target/classes/com/company/prod/Main
. But I get java.lang.ClassNotFoundException: target.classes.com.company.prod.Main
.
I also tried to cd
into the target/classes/com/company/prod/
directory and run java -cp . Main
but then I got Error: Could not find or load main class Main Caused by: java.lang.NoClassDefFoundError: com/company/prod/Main (wrong name: Main)
.
Why is this not working?