场景:工作中的项目都是使用Maven的目录结构,虽然能够如期的完成开发工作,但是对于一个Maven工程的配置却并不熟悉,这里主要介绍下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

++++++++++++++++++++++++++++++++++++++++++++

1.1 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(项目站点文件)。

1.2 项目构建的生命周期的介绍

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 Javaclasses.

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的构建生命周期也是可以扩展和自定义的,这里就先不做介绍了。

参照:http://hi.baidu.com/mylovechangchu/blog/item/fbda36da3644a6dfb6fd48d6.html

APACHE原址:http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

1.3 Maven工程添加新文件夹

新建立的Maven工程是没有resources文件夹的,需要自己去创建。

步骤分为两步:

1、在src的main和test目录下分别建立resources文件夹

2、按照下图所示添加即可

(转)Maven项目标准目录结构的更多相关文章

  1. Maven项目标准目录结构

    -----------------------siwuxie095 Maven 项目标准目录结构 1.Maven 项目分为两种 (1)Java 项目 (2)Web 项目 2.对于 Java 项目 其中 ...

  2. Android MAVEN项目标准目录结构

    1.标准目录结构: src -main      –bin 脚本库      –java java源代码文件      –resources 资源库,会自动复制到classes目录里      –fi ...

  3. MAVEN项目标准目录结构 ;

    http://blog.csdn.net/lengyue_wy/article/details/6718637 版权声明:本文为博主原创文章,未经博主允许不得转载.    1.标准目录结构: src ...

  4. MAVEN项目标准目录结构(转)

    转自:http://blog.csdn.net/lengyue_wy/article/details/6718637 版权声明:本文为博主原创文章,未经博主允许不得转载.    1.标准目录结构: s ...

  5. Maven项目的目录结构+maven的安装与配置

    1.首先下载maven,然后配置环境变量,在MyEclipse里面配置maven 2.配置maven的pom.xml文件 3.下载和更新资源 右击项目,有一个Maven4Myeclipse,里面有三个 ...

  6. Maven项目的目录结构

    刚接触Maven没多长时间,实习时在的小公司很不规范,所有web项目都是dynamic web project搭建,没有用到项目构建,管理工具,导致了非常多的重复工作与低效. 先来看看Maven的功能 ...

  7. maven项目eclipse目录结构浅析

    maven项目eclipse目录结构浅析 PS:Java Resources是为了方便我们编译,到最后都会编译到   WEB-INF/classes Maven项目的目录结构

  8. Idea中新建maven项目的目录结构

    maven项目的目录结构如下所示 pom.xml文件内容如下所示 <?xml version="1.0" encoding="UTF-8"?> &l ...

  9. 新建标准mavenWeb工程以及Maven的web应用标准目录结构建议

    到现在为止,使用Maven结构的Web工程越来越多,因此在此介绍一下通过Maven来构建项目的相关知识.     文档主要分为两部分:       1.如何通过maven来构建多模块的web项目    ...

随机推荐

  1. 使用MySQLdb操作Mysql数据库

    MySQLdb简介 MySQL是一个小型关系型数据库管理系统,开发者为瑞典MySQLAB公司.在2008年1月16号被Sun公司收购.目前MySQL被广泛地应用在Internet上的中小型网站中.由于 ...

  2. Spring学习(21)--- AOP之Advice应用(上)

    前置通知(Before advice) 在某个连接点(join point)之前执行的通知,但不能阻止连接点前的执行(除非它抛出异常) 返回后通知(After returning advice) 在某 ...

  3. tcp/ip详解 卷1 -- 链路层

    以太网 以太网指数字设备公司,英特尔公司,Xeror公司在 1982年联合公布的一个标准, 是当前 TCP/IP 采用的主要局域网技术. 以太网采用 CSMA/CD 的媒体接入方法, 即 带冲突检测的 ...

  4. 有关Dom的一些操作

    学习前端的都会了解到一些Dom操作,让我们来看看Dom操作有哪些吧! DOM(即 Document Object Mode) 是 W3C(万维网联盟)的标准. DOM 定义了访问 HTML 和 XML ...

  5. Tomcat7的热部署

    所谓热部署就是在tomcat不停机的情况下,将新的war包放上去,达到服务不中断,用户无察觉的目的,实现的原理很简单,这里做下记录,以便后期查看. 1.1 安装tomcat7 略 1.2 在tomca ...

  6. 如何编写一个带命令行参数的Python文件

    看到别人执行一个带命令行参数的python文件,瞬间觉得高大上起来.牛逼起来,那么如何编写一个带命令行参数的python脚本呢?不用紧张,下面将简单易懂地让你学会如何让自己的python脚本,支持带命 ...

  7. 第一章:windows下 python 的安装和使用

    1. 主流的python版本和大部分人使用的版本都是 2.7 和3.6 2.安装 python2.7 和 python3.6的步骤 1. 下载 python对应的版本:选择使用的 系统, 64位和32 ...

  8. 一张图告诉你angular2所有知识点

    忙活了半年,从angular2.0到现在angular4.2.从没AOT到有AOT.我想说,angular2的学习曲线真的有点陡峭.只能说,angular2是一个比较完整的框架,框架就是这样,一大堆条 ...

  9. [转]ubuntu搭建LAMP环境

    首先下载安装apache2 输入:sudo apt-get install apache2 安装完毕后,在浏览器中输入:localhost 可以看到apache的默认主页 紧接着安装php5 输入:s ...

  10. servlet+jsp导入Excel到mysql数据库

    package khservlet; import java.io.FileInputStream;import java.io.IOException;import java.io.InputStr ...