Maven directory structure

2020-08-21 03:18发布

问题:

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?

回答1:

Add sourceDirectory to the build tag in the pom file.

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

Here is the relevant section in the maven docs.



回答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.



回答3:

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]


标签: java maven-2