2018-10-3 更新:
官方推荐的已经更新为这样:
src/main/java | Application/Library sources |
src/main/resources | Application/Library resources |
src/main/filters | Resource filter files |
src/main/webapp | Web application sources |
src/test/java | Test sources |
src/test/resources | Test resources |
src/test/filters | Test resource filter files |
src/it | Integration Tests (primarily for plugins) |
src/assembly | Assembly descriptors |
src/site | Site |
LICENSE.txt | Project's license |
NOTICE.txt | Notices and attributions required by libraries that the project depends on |
README.txt | Project's readme |
原文链接:(https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html)
很不错的翻译,里面还有maven官网的其他翻译:(http://ifeve.com/maven-standard-directory-layout/)
我的原文里的英文版应该也是官方的,只是官方也会更新嘛。可以看出,官方增加了it目录,把assembly目录也移动了。我觉得这样的改动,也是挺有道理的。
至于转载的,是有点乱来的,至少应该没有什么bin目录。config应该也没有。
那么我的shell放哪呢?比如,可能像MyCAT一样,assembly里放bin,bin里放脚本。因为一般,脚本也是用来装配、组装时用的吧?
filter是很常用的。但我很少见人用。资源过滤是常见的事情,比如对于生产没用的文件,多环境发布的文件等。
翻译过来是这样:
有一个公共的目录结构考虑到用户对一个Maven项目能马上找到家的感觉就算在另外一个Maven项目。这个好处是类似于网站范围内的外观和感觉。
下一个选项文档目录结构为Maven的预期和目录结构油Maven创建。请尽可能地尝试确认这个结构。无论如何,你不能设置那些由项目描述符重写的。
src/main/java | 程序/类库的源码 |
---|---|
src/main/resources | 程序/类库的资源 |
src/main/filters | 资源过滤文件 |
src/main/webapp Web | 程序源码 |
src/test/java | 测试源码 |
src/test/resources | 测试资源 |
src/test/filters | 测试资源过滤 |
src/it Integration | 单元测试 (主要的插件) |
src/assembly | 装配描述符 |
src/site | 站点 |
LICENSE.txt | 项目的许可证 |
NOTICE.txt | 项目所依赖的类库所需的通知和归属 |
README.txt | 项目的描述文件 |
在最顶级的项目描述文件:一个 pom.xml文件。此外,这个文本文件意味着用户可以很快地读并接收源码:README.txt,LICESE.txt,等等。
这里两个子目录结构:src 和 target.这里只有其他被期望的目录,类似于CVS,.git*,.svn,和在多模块项目构建的任何子项目(每一个将被安排如上)。
target 目录被用于构建输出目录。 src 目录包含项目构建,生成站点等等的所有源码材料。它包含了一个为不同类型的子目录: main目录为了主构建工件,test 目录为单元测试代码和资源,site等等。
在工件生产源码目录(例如: main和test),这里的一个目录是为了java(其中存在正常包装层次在),和一个resources目录(这个结构会被拷贝到target的classpath目录作为默认的资源定义)
如果这里有其他贡献源码来构建工件,它们将被放到其他子目录:例如 src/main/antlr将包含Antlr语法定义的文件。
> ps:加了这么多东西,转载改为原创了。:)
-----
ouyida3注:WEB-INF路径,更多的是使用webapp,而不是webapps。下面的表格`src/main/webapps`有错。--2015.8.3
-----
2014-10-26 11:46原文:
转 原标题:Maven 目录结构的解析
1.标准目录结构:
src
-main
–bin 脚本库
–java java源代码文件
–resources 资源库,会自动复制到classes目录里
–filters 资源过滤文件
–assembly 组件的描述配置(如何打包)
–config 配置文件
–webapp web应用的目录。WEB-INF、css、js等
-test
–java 单元测试java源代码文件
–resources 测试需要用的资源库
–filters 测试资源过滤库
-site Site(一些文档)
target
LICENSE.txt Project’s license
README.txt Project’s readme
工程根目录下就只有src和target两个目录
target是有存放项目构建后的文件和目录,jar包、war包、编译的class文件等。
target里的所有内容都是maven构建的时候生成的
参照:http://breath.iteye.com/blog/1005447
++++++++++++++++++++++++++++++++++++++++++++
Maven项目的标准目录介绍
Maven提倡使用一个共同的标准目录结构,使开发人员能在熟悉了一个Maven工程后,对其他的Maven工程也能清晰了解。这样做也省去了很多设置的麻烦。
以下的文档介绍是Maven希望的目录结构,并且也是目录创建工程是采用的目录结构。Maven推荐大家尽可能的遵守这样的目录结构。
src/main/java | Application/Library sources |
src/main/resources | Application/Library resources |
src/main/filters | Resource filter files |
src/main/assembly | Assembly descriptors |
src/main/config | Configuration files |
src/main/webapps | Web application sources |
src/test/java | Test sources |
src/test/resources | Test resources |
src/test/filters | Test resource filter files |
src/site | Site |
LICENSE.txt | Project's license |
README.txt | Project's readme |
在顶级目录上是工程的描述文件pom.xml(如果使用Ant则还包括其他属性文件,maven.xml或build.xml),另外还包括提供给最终用户的文件,如,README.txt,LICENSE.txt等等。
顶级目录还包括两个子目录:src,target。顶级目录下可能出现的其他目录仅仅是CVS或.svn和其他多模块工程的工程目录,最好不要再有其他目录。
Target目录是所有工程编译构建的输出目录。
Src目录包含所有工程的源码文件,配置文件,资源文件等等。它下面的子目录一般包含main(主要的工程源文件),test(测试文件),site(项目站点文件)。
项目构建的生命周期的介绍
Maven 2是围绕着构建生命周期概念设计的。这意味着,构建或者发布的过程已经被清晰的定义了。
当我们使用Maven构建工程时,我们只需要了解几个Maven定义好的命令即可,其他的工作则交给POM来完成。
以下给出Maven提供的构建生命周期列表:
validate | validate the project is correct and all necessary information is available. |
generate-sources | generate any source code for inclusion in compilation. |
process-sources | process the source code, for example to filter any values. |
generate-resources | generate resources for inclusion in the package. |
process-resources | copy and process the resources into the destination directory, ready for packaging. |
compile | compile the source code of the project. |
process-classes | post-process the generated files from compilation, for example to do bytecode enhancement on Java classes. |
generate-test-sources | generate any test source code for inclusion in compilation. |
process-test-sources | process the test source code, for example to filter any values. |
generate-test-resources | create resources for testing. |
process-test-resources | copy and process the resources into the test destination directory. |
test-compile | compile the test source code into the test destination directory |
test | run tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed. |
package | take the compiled code and package it in its distributable format, such as a JAR. |
pre-integration-test | perform actions required before integration tests are executed. This may involve things such as setting up the required environment. |
integration-test | process and deploy the package if necessary into an environment where integration tests can be run. |
post-integration-test | perform actions required after integration tests have been executed. This may including cleaning up the environment. |
verify | run any checks to verify the package is valid and meets quality criteria. |
install | install the package into the local repository, for use as a dependency in other projects locally. |
deploy | done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. |
因此,当我们构建一个项目时,只需要了解自己希望做什么,然后执行以上对应的生命周期即可。
例如,我们希望编译我们的工程。在命令行状态下进入到工程的pom.xml文件所在的目录中,使用命令:mvn compile;希望构建打包我们的工程,使用mvn package即可。
当然了,maven的构建生命周期也是可以扩展和自定义的,这里就先不做介绍了。