如何使用myeclipse搭建maven项目 ssm工程
一.maven介绍
Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件。(来源百度百科)
二.在官网下载maven软件包
https://maven.apache.org/download.cgi
进入这个页面下载maven软件包。
下载maven apach-maven-3.6.1-bin.zip版本。
下载完成后解压文件,在E盘下创建maven目录,将文件解压后的文件放入这个目录。(切记目录中不应该有中文)
三.完成maven环境变量配置
首先,应该配置环境变量。
右击此电脑,选择属性选项,进入系统界面,选择高级系统设置
然后进入系统属性界面,选择环境变量。
进入环境变量配置界面,先配置用户环境变量 MAVEN_HOME,目录应该是我们解压的maven目录。
浏览目录,在计算机中找到之前的目录就可以了。
接下来配置系统环境变量,在系统环境变量中找到path变量,点击编辑。
点击新建,输入我们之前放maven的目录,打开bin目录将地址栏的目录粘贴过来就可以了,然后确定即可。
环境变量配置完成,开始测试maven是否成功。使用mvn -v命令来进行测试。
win+R键打开运行,输入cmd回车,打开cmd命令框,输入mvn -v回车,如果出现如下图的样式说明我们的配置成功了。
如果提示不是内部命令,证明maven步骤有问题,或者路径有中文。
四.配置仓库
1.首先,打开maven存放的位置,打开conf文件夹,打开setting.xml文件。
打开后,找到如图的本地资源库,在下边修改默认资源库路径到E盘下边,后边跟的文件名会自动创建文件夹。
2.修改镜像为阿里云和开源中国,在镜像配置标签内部添加如下代码。
<mirror>
<!--阿里云镜像-->
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>ui</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://uk.maven.org/maven2/</url>
</mirror>
<mirror>
<id>ibiblio</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
<!--访问慢的网址放入到后面 开源中国镜像-->
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>net-cn</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://maven.net.cn/content/groups/public/</url>
</mirror>
<mirror>
<id>JBossJBPM</id>
<mirrorOf>central</mirrorOf>
<name>JBossJBPM Repository</name> <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
</mirror>
这样子资源库和镜像就配置完毕了。
五.myeclipse集成maven
打开myeclipse->window->preferences->搜索maven
点击应用,点击ok,就完成了myeclipse中集成maven的操作。
六.maven创建web工程(ssm项目)
一直点击next,切记要自动生成web.xml文件。
将标准的java企业级项目改为标准的maven企业级项目构建。
取消之后点击完成。
创建完成后项目目录。
maven目录个文件夹作用。
七.配置pom.xml文件生成资源库
因为oracle数据库的驱动包,maven无法生成,所以需要我们自己进行安装oracle数据库的驱动包。
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=10.2.0.2.0 -Dpackaging=jar -Dfile=D:/mylib/ojdbc6.jar
这段代码是cmd命令,它的作用就是给maven添加oracle数据库的驱动包,最后的目录应该是自己本地的ojdbc.jar的目录。
出现这样的显示框表示oracle驱动包安装成功,注意应该在myeclipse项目的web_inf目录下建立lib文件夹,将oracle的驱动包考入其中否则会报错。
下边是ssm架构的pom.xml文件:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- spring版本号 -->
<spring.version>4.1.6.RELEASE</spring.version>
<!-- mybatis版本号 -->
<mybatis.version>3.2.6</mybatis.version>
<!-- log4j日志文件管理包版本 -->
<slf4j.version>1.7.7</slf4j.version>
<log4j.version>1.2.17</log4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.2</version>
</dependency>
<!-- mybatis 逆向工程jar -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<!-- 表示开发的时候引入,发布的时候不会加载此包 -->
<scope>test</scope>
</dependency>
<!-- spring核心包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</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-oxm</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-jdbc</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-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- mybatis核心包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!-- mybatis/spring包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
<!-- 导入java ee jar 包 -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<!-- 导入Mysql数据库链接jar包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
<!-- c3p0连接池jar -->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<!-- 导入dbcp的jar包,用来在applicationContext.xml中配置数据库 -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<!-- JSTL标签类 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- 日志文件管理包 -->
<!-- log start -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- 格式化对象,方便输出日志 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.41</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- log end -->
<!-- 映入JSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- 上传组件包 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
pom.xml文件配置完成后会自动下载相关的jar包以及源码包和doc文档,路径是之前我们配置的资源库目录。(即在settings.xml文件中配置的目录)。
以上就是maven构建ssm的全过程,有什么不对的地方,希望谅解请各位大神指正。感谢。