9

I'm new to Maven and I've been reading all morning tutorials (amazing tool).

This new Java project I started looking at however doesn't use the default directory structure. Instead of src/main/java for sources it uses something like src/org/myapp.

When I run mvn package on the project (where pom.xml is located) I get a message saying that no Sources have been compiled because it's not able to find them (the source path being different).

Is there a way to specify your own sources path in Maven?

Luca Matteis
  • 29,161
  • 19
  • 114
  • 169

3 Answers3

11

Add sourceDirectory to the build tag in the pom file.

<build>
    ...
 <sourceDirectory>src</sourceDirectory>
    ...
</build>

Here is the relevant section in the maven docs.

dogbane
  • 266,786
  • 75
  • 396
  • 414
2

In theory, you can use a non-standard directory structure for your Maven project. In practice, you may find that various Maven plugins and IDE integrations won't work properly. So I'd advise that you reorganize your project directory structure to be what Maven expects ... before you get lots of version control history and other stuff that will make reorganization more painful.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 3
    I disagree. There are standard ways for a well-behaved plugin to find out what the directory structure is. A plugin that uses `model.getBuild().getSourceDirectory()` will always find the source directory, no matter where it's at. And a plugin that just checks for `new File("src/main/java")` is probably a pretty bad plugin in other respects, too. – Sean Patrick Floyd Oct 28 '10 at 10:07
  • But I also agree that it's a good idea to use the standard structure if you have the choice. – Sean Patrick Floyd Oct 28 '10 at 10:08
  • @seanizer - the problem is that plugins and other stuff is unlikely to be as well tested with POMs that use non-standard directory structures. And you probably get an enthusiastic response from the Maven developers to any bugs that you uncover. – Stephen C Oct 28 '10 at 10:16
  • I agree that the road will be rockier. But I also think all major plugins should deal well with this situation. – Sean Patrick Floyd Oct 28 '10 at 10:21
  • Ooops ... I meant " ... an UN-enthusiastic response ..." . – Stephen C Oct 28 '10 at 11:57
1

How did you create the project? The idea way to create a new maven project is: mvn archetype:create and then follow the instructions.

Read this for more details

Update to extend by answer based on the URL:

mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id]
zengr
  • 38,346
  • 37
  • 130
  • 192