tags:

views:

65

answers:

3

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?

A: 

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
+5  A: 

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
But is creating a new project from eclipse menu and using it for maven a good practice?
zengr
I don't think it's a new project. Sounds like he is trying to migrate an existing project (with a different directory structure) to maven. But I could be wrong...
dogbane
@zengr, I'm not using Eclipse
Luca Matteis
A: 

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
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.
seanizer
But I also agree that it's a good idea to use the standard structure if you have the choice.
seanizer
@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
I agree that the road will be rockier. But I also think all major plugins should deal well with this situation.
seanizer
Ooops ... I meant " ... an UN-enthusiastic response ..." .
Stephen C
thought so ... :-)
seanizer