Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: No sources to compile

Tags:

java

spring

maven

I am following the 'Build Java Projects with Maven' (https://spring.io/guides/gs/maven/#scratch) and when I run 'mvn compile' from /Users/Misha/Desktop/src/main/java/hello, I get this prompt:

[INFO] Scanning for projects...    [INFO]                                                                                   [INFO] ------------------------------------------------------------------------    [INFO] Building gs-maven 0.1.0     [INFO] ------------------------------------------------------------------------    [INFO]     [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ gs-maven ---    [INFO] Using 'UTF-8' encoding to copy filtered resources.    [INFO] Copying 3 resources    [INFO]     [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ gs-maven ---    [INFO] No sources to compile    [INFO] ------------------------------------------------------------------------    [INFO] BUILD SUCCESS      [INFO] ------------------------------------------------------------------------     [INFO] Total time: 0.942 s     [INFO] Finished at: 2015-01-11T23:10:28-08:00    [INFO] Final Memory: 7M/155M [INFO] ------------------------------------------------------------------------ 

I have the two java files and the xml file in the hello directory, and I am assuming that I should see "Hello World!" instead of No sources to compile. Why is my java code not compiling? Thanks!

like image 849
Mikhail Vega Avatar asked Jan 12 '15 07:01

Mikhail Vega


2 Answers

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.

like image 177
piet.t Avatar answered Sep 20 '22 04:09

piet.t


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.

like image 40
Cameron Hudson Avatar answered Sep 17 '22 04:09

Cameron Hudson