Maven: No sources to compile

Are you try to compile project or class ? As the guideline in https://spring.io/guides/gs/maven/#scratch you need to compile for project. Try to run mvn compile from project direction.


In my case, I was missing this:

<project>
    ...
    <build>
        <sourceDirectory>src</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>
    </build>
    ...
</project>

Normally, I'd just use the default directory structure

  • src/main/java as a source folder.
  • src/test/java as a test folder.

But I'm working on a class project with existing code, and can't rearrange the file structure.


To create a maven-project you need

  1. A project-directory containing the pom.xml-file
  2. Within this project-directory a subdirectory src/main/java containing your java-code (packages go to subdirectories of src/main/java)

To invoke maven run mvn compile or something similar from the project-directory.


because there are no java files in $PROJECT_DIR/src/main/java

Tags:

Java

Maven

Spring