简体   繁体   English

Maven目录结构

[英]Maven directory structure

I'm new to Maven and I've been reading all morning tutorials (amazing tool). 我是Maven的新手,我一直在阅读所有早上的教程(神奇的工具)。

This new Java project I started looking at however doesn't use the default directory structure. 然而,我开始研究的这个新Java项目不使用默认目录结构。 Instead of src/main/java for sources it uses something like src/org/myapp . 它不使用src/main/java作为源代码,而是使用类似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). 当我在项目上运行mvn packagepom.xml所在的位置)时,我收到一条消息,说没有编译源,因为它无法找到它们(源路径不同)。

Is there a way to specify your own sources path in Maven? 有没有办法在Maven中指定自己的源路径?

Add sourceDirectory to the build tag in the pom file. sourceDirectory添加到pom文件中的build标记。

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

Here is the relevant section in the maven docs. 以下是maven文档中的相关部分。

In theory, you can use a non-standard directory structure for your Maven project. 理论上,您可以为Maven项目使用非标准目录结构。 In practice, you may find that various Maven plugins and IDE integrations won't work properly. 实际上,您可能会发现各种Maven插件和IDE集成无法正常工作。 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. 因此,我建议你重新组织你的项目目录结构,使其成为Maven所期望的......在你获得大量的版本控制历史记录和其他会使重组变得更加痛苦的事情之前。

How did you create the project? 你是如何创建这个项目的? The idea way to create a new maven project is: mvn archetype:create and then follow the instructions. 创建新maven项目的想法是: mvn archetype:create然后按照说明操作。

Read this for more details 阅读本文了解更多详情

Update to extend by answer based on the URL: 更新以基于URL的答案进行扩展:

mvn archetype:create -DgroupId=[your project's group id] -DartifactId=[your project's artifact id]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM