zoukankan      html  css  js  c++  java
  • Maven项目的目录结构

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

      先来看看Maven的功能下面是来自于百度百科:Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目。由于 Maven 的面向项目的方法,许多 Apache Jakarta 项目发文时使用 Maven,而且公司项目采用 Maven 的比例在持续增长。

      首先构建一个Maven项目,网上有很多介绍,就不重复了。整个Maven项目里很重要的就是这个pom文件。pom就是用来专门管理项目中用到的各种资源,包括jar包,jdbc驱动等,只要在pom中写下如下格式的xml,就能够自动为你下载部署该开发包(这是我的项目中的pom文件,也是在网上找的):

      1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      3   <modelVersion>4.0.0</modelVersion>
      4   <groupId>com.myapp.lxiao</groupId>
      5   <artifactId>MavenSSH</artifactId>
      6   <packaging>war</packaging>
      7   <version>0.0.1-SNAPSHOT</version>
      8   <name>MavenSSH Maven Webapp</name>
      9   <url>http://maven.apache.org</url>
     10   <dependencies>
     11       <!-- 添加mysql jdbc驱动 -->
     12       <dependency>
     13         <groupId>mysql</groupId>
     14         <artifactId>mysql-connector-java</artifactId>
     15         <version>5.1.34</version>
     16     </dependency>
     17     <dependency>
     18       <groupId>junit</groupId>
     19       <artifactId>junit</artifactId>
     20       <version>3.8.1</version>
     21       <scope>test</scope>
     22     </dependency>
     23     <!-- struts2核心包 -->
     24     <dependency>
     25         <groupId>org.apache.struts</groupId>
     26         <artifactId>struts2-core</artifactId>
     27         <version>2.3.1.2</version>
     28     </dependency>
     29     <!-- structs2与spring整合  -->
     30     <dependency>
     31         <groupId>org.apache.struts</groupId> 
     32            <artifactId>struts2-spring-plugin</artifactId> 
     33         <version>2.3.1.2</version> 
     34     </dependency>
     35     <!-- 在 Struts2中要使用 Ajax获得Json数据。要使用Ajax必须引用此Jar -->
     36     <dependency> 
     37         <groupId>org.apache.struts</groupId> 
     38         <artifactId>struts2-json-plugin</artifactId> 
     39         <version>2.3.1.2</version> 
     40     </dependency>
     41     <!-- Hibernate核心包 -->
     42     <dependency> 
     43         <groupId>org.hibernate</groupId> 
     44         <artifactId>hibernate-core</artifactId> 
     45         <version>3.6.10.Final</version> 
     46     </dependency>
     47     <!-- spring3可选的依赖注入,不可缺少 -->
     48     <dependency> 
     49         <groupId>org.aspectj</groupId> 
     50         <artifactId>aspectjweaver</artifactId> 
     51         <version>1.7.3</version> 
     52     </dependency>
     53     <!-- 扩展Java类与实现Java接口 -->
     54     <dependency> 
     55         <groupId>cglib</groupId> 
     56         <artifactId>cglib</artifactId> 
     57         <version>2.2</version> 
     58     </dependency>
     59     <!-- 运用Log4j必须用到这个包 -->
     60     <dependency> 
     61         <groupId>org.slf4j</groupId> 
     62         <artifactId>slf4j-api</artifactId> 
     63         <version>1.7.5</version> 
     64         <scope>compile</scope> 
     65     </dependency>
     66     <!-- Spring包 -->
     67     <!-- Spring核心包 -->
     68     <dependency>
     69         <groupId>org.springframework</groupId>
     70         <artifactId>spring</artifactId>
     71         <version>2.5.6</version>
     72         <type>jar</type> 
     73     </dependency>
     74     <!-- Spring在WEB上的MVC框架上加上这个包 -->
     75     <dependency> 
     76         <groupId>org.springframework</groupId> 
     77         <artifactId>spring-webmvc</artifactId> 
     78         <version>3.2.3.RELEASE</version> 
     79         <type>jar</type> 
     80         <scope>compile</scope> 
     81     </dependency>
     82     <!-- log4j日志包 -->
     83     <dependency> 
     84         <groupId>log4j</groupId> 
     85         <artifactId>log4j</artifactId> 
     86         <version>1.2.16</version> 
     87         <scope>compile</scope> 
     88     </dependency>
     89     <!-- jsp接口 -->
     90     <dependency> 
     91         <groupId>javax.servlet.jsp</groupId> 
     92         <artifactId>jsp-api</artifactId> 
     93         <version>2.1</version> 
     94         <scope>provided</scope> 
     95     </dependency>
     96     <!-- 连接池 -->
     97     <dependency> 
     98         <groupId>c3p0</groupId> 
     99         <artifactId>c3p0</artifactId> 
    100         <version>0.9.1.2</version> 
    101     </dependency>
    102     <!-- servlet接口 -->
    103     <dependency> 
    104         <groupId>javax.servlet</groupId> 
    105         <artifactId>servlet-api</artifactId> 
    106         <version>2.5</version> 
    107         <scope>provided</scope> 
    108     </dependency>
    109     <!-- Mysql数据库JDBC连接包 -->
    110     <dependency> 
    111         <groupId>mysql</groupId> 
    112         <artifactId>mysql-connector-java</artifactId> 
    113         <version>5.1.26</version> 
    114         <scope>compile</scope> 
    115     </dependency>
    116   </dependencies>
    117   <build>
    118     <finalName>MavenSSH</finalName>
    119   </build>
    120 </project>

    然后我们来看一下Maven项目的目录结构,能够知道不同程序,文件都放到哪些文件夹下。

    src/main/java application library sources - java源代码文件
    src/main/resources application library resources - 资源库,会自动复制到classes文件夹下
    src/main/filters resources filter files - 资源过滤文件
    src/main/assembly assembly descriptor - 组件的描述配置,如何打包
    src/main/config configuration files - 配置文件
    src/main/webapp web application sources - web应用的目录,WEB-INF,js,css等
    src/main/bin 脚本库
    src/test/java 单元测试java源代码文件
    src/test/resources 测试需要的资源库
    src/test/filters 测试资源过滤库
    src/site 一些文档
    target/ 存放项目构建后的文件和目录,jar包,war包,编译的class文件等;Maven构建时生成的
    pom.xml 工程描述文件
    LICENSE.txt license
    README.txt read me

    知道了maven的目录结构,我们就可以在各自的目录下创建对应的文件了。

    引用:http://blog.csdn.net/robinjwong/article/details/38687713

  • 相关阅读:
    HDFS文件系统
    使用cmake安装单实例mysql
    python读取数据库表数据并写入excel
    linux文件行数统计
    ORACLE清空回收站操作
    Oracle 11g静默安装
    图解Java设计模式之职责链模式
    图解Java设计模式之策略模式
    图解Java设计模式之状态模式
    图解Java设计模式之解释器模式
  • 原文地址:https://www.cnblogs.com/lxiao/p/4337708.html
Copyright © 2011-2022 走看看