web项目环境搭建(1):建立一个maven项目
一、maven简介以及常用概念
1.Maven是一个项目管理和整合的工具。Maven为开发者提供了一套完整的构建生命周期框架。开发团队基本不用花多少时间就能自动完成工程的基础构建配置,因为Maven使用了一个标准的目录结构和一个默认的构建生命周期。在创建报告、检查、构建和测试自动配置时,Maven可以让开发者的工作变得更简单。
maven可以做的事: 构建、文档生成、报告、依赖、 SCMs(software configuration Management)、发布、分发 、邮件列表。
Maven使用约定而不是配置,意味着开发者不需要再自己创建构建过程。当创建Maven工程时,Maven会创建默认的工程结构,开发者只需要合理的放置配置文件而在pom.xml中无需做任何配置。
2.首先分享一个maven中央仓库: http://www.mvnrepository.com/
进入之后,搜索你要的jar包名,从相应的版本进入,把pom依赖复制到项目的pom.xml文件,重新mvn eclipse:eclipse就可以自动下载回依赖包了,很方便
3.常用概念
groupId:组织名称,举个例子,比如spring项目,它的groupId是 org.springframework,这是一个唯一的名称,用来形容整个项目。
artifactId:具体项目名称,比如spring项目,的一个bean子项目的artifactId是spring-beans
version:版本号
二、用eclipse创建maven项目
(1)打开eclipse,新建一个maven project,next,选择一个archetype(骨架),这里选择maven-archetype-quickstart,
(2)输入groupId:com.bench.app.ebuy,artifactId:ebuy
(3)再选择finish,eclipse就自动帮你建立好了一个工程了
(5)打开你的ebuy,会看到最底下有一个pom.xml文件,是用来管理这个项目的信息的,如版本,依赖项。
(6)以前都是把需要的jar拷过来,复制到工程下面,但是一旦需要换版本,又得重新找jar包,下载,拷贝,很繁琐,现在只需要在pom.xml里面写,就能自动导入了。
(7)找到dependencies标签,这里面是项目用到的所有依赖,首先加入一个junit
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
按下保存,相应的jar包就会被下载回本地maven仓库,并且导入到工程里来。当然,如果你是第一次操作,会比较慢,因为eclipse会从中央仓库下载junit和其他必要的组件。
上面是添加了junit依赖,还可以添加其他依赖。
小缺点
这里的版本号是写死的,如果要修改版本号,还要去dependcy里面改,这里把版本号单独提出来。
加入一个标签如下
<properties>
<!-- spring -->
<spring.version>4.1.7.RELEASE</spring.version>
<!-- junit -->
<junit.version>4.12</junit.version>
<!-- MyBatis -->
<mybatis.version>3.3.0</mybatis.version>
<mybaitsSpring.version>1.2.3</mybaitsSpring.version>
<!-- 连接mysql -->
<mysqlConnec.version>5.1.36</mysqlConnec.version>
<!-- log4j -->
<log4j.version>1.2.17</log4j.version>
<!-- velocity -->
<velocity.version>1.7</velocity.version>
<velocityTools.version>2.0</velocityTools.version>
</properties>
刚才的junit依赖可以这样写了
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
以下是这个项目完整的pom文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bench.app.ebuy</groupId>
<artifactId>ebuy</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>ebuy Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<!-- spring -->
<spring.version>4.1.7.RELEASE</spring.version>
<!-- junit -->
<junit.version>4.12</junit.version>
<!-- MyBatis -->
<mybatis.version>3.3.0</mybatis.version>
<mybaitsSpring.version>1.2.3</mybaitsSpring.version>
<!-- 连接mysql -->
<mysqlConnec.version>5.1.36</mysqlConnec.version>
<!-- log4j -->
<log4j.version>1.2.17</log4j.version>
<!-- velocity -->
<velocity.version>1.7</velocity.version>
<velocityTools.version>2.0</velocityTools.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysqlConnec.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${mybaitsSpring.version}</version>
</dependency>
<!-- 添加servlet支持 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-tools</artifactId>
<version>${velocityTools.version}</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>${velocity.version}</version>
</dependency>
</dependencies>
<build>
<finalName>ebuy</finalName>
</build>
</project>
web项目环境搭建(1):建立一个maven项目的更多相关文章
- Django项目: 项目环境搭建 ---- 一、创建django项目
项目环境搭建 一.创建django项目 1.创建python虚拟环境 在虚拟机上创建python虚拟环境,因为实际项目部署,实在linux mkvirtualenv -p /usr/bin/pytho ...
- 怎么在本地建立一个Maven 项目push到码云(https://git.oschina.net)
本地建立一个的mvan项目不使用SmartGit push到码云上. 1 首先在自己码云的建立一个maven 空项目 2 然后打开STS(Spring Tool Suite) 新建一个Maven( ...
- idea建立一个maven项目
前言:虽然之前实习的时候有过spring框架的实践,但是因为基本上都是在已有的基础上进行修修补补,并没有对Spring框架有深刻的理解.所以从今天起,要从零开始对Spring框架进行学习.在此之前,第 ...
- 建一个maven项目
建一个普通的maven项目(eclipse) 需要的jar和文件: eclipse :jdk1.8.0_144 maven:apache-maven-3.5.3 进入(下载):http:// ...
- jenkins 构建一个maven项目
1.首先在 全局工具配置 里配置maven的路径信息 这里因为之前已经下载了maven并放在了E盘,因此只需要在 MAVEN_HOME 添加maven文件夹的路径 如若本地还没maven,勾选 “自动 ...
- Hadoop项目开发环境搭建(Eclipse\MyEclipse + Maven)
写在前面的话 可详细参考,一定得去看 HBase 开发环境搭建(Eclipse\MyEclipse + Maven) Zookeeper项目开发环境搭建(Eclipse\MyEclipse + Mav ...
- web项目环境搭建(2):整合SpringMVC+velocity
velocity是一个基于java的模板引擎.velocity应用于web开发时,前端设计人员可以只关注页面的显示效果,而java程序人员只关注业务逻辑代码.velocity将java代码从web页面 ...
- Hive项目开发环境搭建(Eclipse\MyEclipse + Maven)
写在前面的话 可详细参考,一定得去看 HBase 开发环境搭建(Eclipse\MyEclipse + Maven) Zookeeper项目开发环境搭建(Eclipse\MyEclipse + Mav ...
- maven Spring+Spring MVC+Mybatis+mysql轻量级Java web开发环境搭建
之前一直在做的一个GIS系统项目,采用了jsp+servlet框架,数据传输框架采用了apache的thrift框架,短时多传的风格还不错,但是较其他的java web项目显得有点太臃肿了,现在给大家 ...
随机推荐
- Kafka 集群消息监控系统:Kafka Eagle
Kafka Eagle 1.概述 在开发工作当中,消费 Kafka 集群中的消息时,数据的变动是我们所关心的,当业务并不复杂的前提下,我们可以使用 Kafka 提供的命令工具,配合 Zookeeper ...
- 转:精心挑选的12款优秀 jQuery Ajax 分页插件和教程
在这篇文章中,我为大家收集了12个基于 jQuery 框架的 Ajax 分页插件,这些插件都提供了详细的使用教程和演示.Ajax 技术的出现使得 Web 项目的用户体验有了极大的提高,如今借助优秀的 ...
- Web应用指纹识别
http://danqingdani.blog.163.com/blog/static/186094195201493121834603/
- Chapter 7 Backup and Recovery 备份和恢复:
Chapter 7 Backup and Recovery 备份和恢复: Table of Contents 7.1 Backup and Recovery Types 7.2 Database Ba ...
- 【HDOJ】2416 Treasure of the Chimp Island
bfs().题目的数据乱码.应该如下: *****#********* *.......$...* *..***.......* *....*****..* *....******37A *****. ...
- ldd显示可执行模块的dependenc
ldd的作用是打印可执行档依赖的共享库文件.它是glibc的一部分,由Roland McGrath和Ulrich Drepper维护:$ ldd --versionldd (GNU libc) 2.9 ...
- Qt入门(7)——QApplication类
QApplication类管理图形用户界面应用程序的控制流和主要设置.它包含主事件循环,在其中来自窗口系统和其它资源的所有事件被处理和调度.也用于处理应用程序的初始化和结束,并且提供对话管理.它也处理 ...
- Ubuntu14.04 安装QQ国际版wine-qqintl
Ubuntu14.04安装qq国际版方式: 首先下载,链接为: https://pan.baidu.com/s/1boPitVD 密码:jp1j 也可去Ubuntu中文的Kylin(优麒麟)官网下载 ...
- CentOS卸载openoffice
rpm -e `rpm -qa |grep openoffice` `rpm -qa |grep ooobasis` 这样算是比较彻底的
- HDOJ 1014 Uniform Generator(公约数问题)
Problem Description Computer simulations often require random numbers. One way to generate pseudo-ra ...