Search code examples
mavenm2e

M2E Removes My Source Directory?


I have an existing library that I am building in Eclipse and have added the Maven nature to my project using m2e to add dependencies. When I convert it to a Maven project, my existing source directory (and my bin) become normal folders. Is there a reason for this? I am new to Maven, so I am likely doing something wrong, just not sure what...

My project structure is as follows:

workspace
  project
    src (in build path)
    resources (in build path)
    bin (output dir)

I tried both "mvn eclipse:eclipse" and right click on project -> Configure -> Convert to Maven Project, and both removed my src and resources folders from my build path, and after changing the structure to the below, changed the output to target/test-cases. Even if I manually adjust the build path and output, my dependencies don't resolve.

workspace
  project
    src (no longer in build path)
    resources (no longer in build path)
    bin  (no longer output)
    target (new output dir)
      test-cases (empty)

Solution

  • I think you have the following structure when working with Eclipse (without Maven):

    /workspace
      /project1
        .project
        /src
        /bin
    

    But Maven want to use the following structure

    /workspace
      /project1
         .project
         pom.xml
         /src
            /main
               /java
               /resources
            /test
               /java
         /target
            /classes
            /test-classes
    

    and so on. So it is normal, that the folder src is no more directly a source folder for Eclipse, but now there are src/main/java, src/main/resources, ...

    So it would be easier in the beginning to start with a new Maven project, and move your original sources to the directories they should belong to. Maven has a long tradition with its "convention over configuration", to deviate from that is possible. Have a look at the answer to "Handling unconventional source directory ..." to fix this.