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

1.首先下载maven,然后配置环境变量,在MyEclipse里面配置maven

2.配置maven的pom.xml文件

3.下载和更新资源

右击项目,有一个Maven4Myeclipse,里面有三个我们用到的选项

1.download resource: 下载pom文件配置的资源

2.update dependencies :更新依赖

3.update project configuration:更新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

原文地址:https://www.cnblogs.com/handsome1013/p/5416459.html