Eclipse下创建Maven风格的Java项目

一、新建Maven项目

1、菜单 -> File -> New -> Other -> Maven -> Maven Project

 Next

 2、选择默认的maven-archetype-quickstart,和命令行创建Maven项目中的项目类型一致的。

3、填写项目信息

Group Id:填写包名,com.sdbi

Artifact Id:填写j2se

然后点击Finish

4、运行App

5、在第2步中也可以不使用maven-archetype-quickstart,那么我们需要在第1步中,勾选“Create a simple project(skip archetype selection)”。

 然后,Next,再填写项目信息。

  三、配置MyBatis连接MySQL

1、打开Maven项目的配置文件pom.xml,原来有junit依赖,再添加mybatis和mysql的依赖。

 1     <dependencies>
 2         <!-- junit依赖包 -->
 3         <dependency>
 4             <groupId>junit</groupId>
 5             <artifactId>junit</artifactId>
 6             <version>4.11</version>
 7             <scope>test</scope>
 8         </dependency>
 9         <!-- mybatis依赖包 -->
10         <dependency>
11             <groupId>org.mybatis</groupId>
12             <artifactId>mybatis</artifactId>
13             <version>3.5.7</version>
14         </dependency>
15         <!-- mysql数据库依赖 -->
16         <dependency>
17             <groupId>mysql</groupId>
18             <artifactId>mysql-connector-java</artifactId>
19             <version>5.1.49</version>
20         </dependency>
21     </dependencies>

效果如下图所示:

原文地址:https://www.cnblogs.com/lihuawei/p/14756111.html