IDEA搭建SSM框架教程 从零开始 SSM+Maven框架搭建教程
项目需求:
使用 : Spring+Mybatis+Spring-mvc 搭建项目 实现用户的登录
开发环境:
intellij idea:2019 + maven:3.5.4 + jdk:1.8
接下来直接开始流水线式教程
搭建不成功别着急 也别在一个问题上卡死 我为了学这个 应该练习了不少于20次,第一次的话 我觉得没有一个人能一次成功!
Maven下载特别慢 直接翻到文章最下面 有解决方法
1、新建项目
2.配置搭建的基础配置
3.一切选择完了以后选择 Next 进入项目名称设置
4,配置项目名称 等等 改成自己的项目名称 也可以默认
项目新建完成了 开始配置项目的整体结构
这个是我项目的结构 搭建的时候可以参考下 如果哪里出问题了 记得看看结构是不是有问题 下面介绍下每个文件夹都是干嘛的
java - 存放项目源代码的 - 包括 : controller 控制层,mapper 接口层 我的 sql映射文件也放在这个里面了(这里不明白先不管往下走) ,pojo实体类,service业务逻辑层 这边非常相似 最初版本的三层模式
resources - 存放项目配置文件的 ,后面文章的配置文件部分都是放在这里的
webapp - 建完项目自动会生成 (一般情况下 有些人就没有 我曾经也没有) 这个没有的话百度 看看 实在不行的话应该是我的锅 我的新建项目过程比较简陋 看看别的博主的 应该能解决 这个里面 有个static的文件夹里面放的就是css , js , images 这些东西 jsp目录就是jsp的内容 路径这边尽量就按照我的来 因为方便后面配置文件
前面基本上都是IDEA怎么新建Maven项目 介绍的不够详细 也可以去参考别的博客 下面直接开始干货 (特别提醒:复制的时候记得把配置文件映射的路径等等改成自己的项目路径 不要无脑的乱来)
1.配置pom.xml 配置pom文件 copy的时候看着点 不要copy
下面这句话自己看着点 这个是防止xml文件不编译的
<resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> <include>**/*.properties</include> <include>**/*.html</include> </includes> </resource> </resources>
<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>hoverObServerApp</groupId> <artifactId>com.24timegcy</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>com.24timegcy Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> <!-- 设置项目编码编码 --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <!-- spring版本号 --> <spring.version>4.3.5.RELEASE</spring.version> <!-- mybatis版本号 --> <mybatis.version>3.4.1</mybatis.version> </properties> <dependencies> <!-- java ee --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> </dependency> <!-- 单元测试 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <!-- 实现slf4j接口并整合 --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.2</version> </dependency> <!-- JSON --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.7</version> </dependency> <!-- 数据库 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.41</version> <scope>runtime</scope> </dependency> <!-- 数据库连接池 --> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</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.3.1</version> </dependency> <!-- Spring --> <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-context</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-tx</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-test</artifactId> <version>${spring.version}</version> </dependency> </dependencies> <build> <finalName>com.24timegcy</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> </plugins> </pluginManagement> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> <include>**/*.properties</include> <include>**/*.html</include> </includes> </resource> </resources> </build> </project>
2.新建 applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <!-- 加载配置文件 *.properties --> <context:property-placeholder location="classpath:jdbc.properties"/> <!--配置数据库 dataSource --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 加载数据库用户名 --> <property name="driverClass" value="${jdbc.driver}"/> <!-- 加载数据库密码 --> <property name="jdbcUrl" value="${jdbc.url}"/> <!-- 加载数据库连接 --> <property name="user" value="${jdbc.username}"/> <!-- 加载数据库驱动 --> <property name="password" value="${jdbc.password}"/> <!-- 最大并发连接数 --> <property name="maxPoolSize" value="30"/> <!-- 最小空闲连接数 --> <property name="minPoolSize" value="5"/> </bean> <!-- 配置sqlsessioFactory --> <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 配置数据源 引用(ref)dataSource(bean) --> <property name="dataSource" ref="dataSource"/> <!-- 加载mybatis 配置文件 --> <property name="configLocation" value="classpath:mybatis.xml"/> <property name="mapperLocations" value="classpath:com/hover/mapper/*Mapper.xml"/> </bean> <!-- 配置扫描包 加载mapper代理对象 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 扫描mapper路径 --> <property name="basePackage" value="com.hover.mapper"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean"/> </bean> <!-- 扫描Service包 --> <context:component-scan base-package="com.hover.service"/> </beans>
3.新建jdbc.properties配置文件 这个是数据库的配置信息 记得里面的东西改成跟你相关的
jdbc.driver=com.mysql.jdbc.Driver #数据库地址 jdbc.url=jdbc:mysql://localhost:3306/24-hourobserver?useUnicode=true&characterEncoding=utf8 #用户名 jdbc.username=root #密码 jdbc.password=1234
4.新建mybatis.xml配置文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org.dtd/mybatis-3-config.dtd"> <configuration> <!-- 开启二级缓存 --> <settings> <!--<setting name="cacheEnabled" value="true"/>--> <!-- 是否开启二级缓存 默认为true --> <setting name="cacheEnabled" value="true"/> <!-- 是否懒加载 --> <setting name="lazyLoadingEnabled" value="true" /> </settings> <typeAliases> <!--批量配置别名--> <package name="com.hover.pojo"/> </typeAliases> </configuration>
新建 spring-mvc.xml 配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd"> <!--1.注解扫描位置--> <context:component-scan base-package="com.hover.controller"/> <mvc:resources location="/static/" mapping="/static/**"></mvc:resources> <mvc:annotation-driven > <!-- 消息转换器 --> <mvc:message-converters register-defaults="true"> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes" value="text/plain;charset=UTF-8"/> </bean> </mvc:message-converters> </mvc:annotation-driven> <!--2.配置映射处理和适配器--> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> <!--3.视图的解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
配置Web.xml配置文件
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <display-name>Archetype Created Web Application</display-name> <!-- 配置SprongIoC容器加载的配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>6000</param-value> </context-param> <!-- 用于初始化SpringIoC容器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <servlet> <servlet-name>DispatcherServlet</servlet-name> <!-- 核心控制器 --> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <!-- 应用启动时,加载servlet --> <load-on-startup>1</load-on-startup> <multipart-config> <location>e:/upimgs</location> <max-file-size>5242880</max-file-size> <max-request-size>10485760</max-request-size> <file-size-threshold>0</file-size-threshold> </multipart-config> </servlet> <servlet-mapping> <!-- 约定优于配置,Spring MVC框架默认加载/WEB-INF/<servlet-name/>开头-servlet.xml作为配置文件载入web工程中--> <servlet-name>DispatcherServlet</servlet-name> <!-- 拦截配置 --> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/WEB-INF/jsp/login.jsp</welcome-file> </welcome-file-list> <!--乱码过滤器--> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
=====================都完了以后配置文件基本上就完事了========================
开始具体的功能部分
1.新建实体类 建在 java-包名-pojo里面 我里面的东西这个请不要照搬 跟着你的数据库来
package com.hover.pojo; import java.util.Date; /** * 用户表 * @author Yang * */ public class Users { private Integer u_id; //用户编号 private Integer r_id; //角色编号 private String u_mobilephone; //手机号 private String u_password; //密码 private Date u_createDate; //注册时间 private String u_weiboaccount; //微信账号 private String u_qqaccount; //QQ账号 private String u_weChataccount; //微博账号 private Integer u_delete; //物理是否被删除 private Userinformation userInfo; //用户详细信息 //无参构造 public Users() { super(); // TODO Auto-generated constructor stub } //全参构造 public Users(Integer u_id, Integer r_id, String u_mobilephone, String u_password, Date u_createDate, String u_weiboaccount, String u_qqaccount, String u_weChataccount, Integer u_delete) { super(); this.u_id = u_id; this.r_id = r_id; this.u_mobilephone = u_mobilephone; this.u_password = u_password; this.u_createDate = u_createDate; this.u_weiboaccount = u_weiboaccount; this.u_qqaccount = u_qqaccount; this.u_weChataccount = u_weChataccount; this.u_delete = u_delete; } //get set public Integer getU_id() { return u_id; } public void setU_id(Integer u_id) { this.u_id = u_id; } public Integer getR_id() { return r_id; } public void setR_id(Integer r_id) { this.r_id = r_id; } public String getU_mobilephone() { return u_mobilephone; } public void setU_mobilephone(String u_mobilephone) { this.u_mobilephone = u_mobilephone; } public String getU_password() { return u_password; } public void setU_password(String u_password) { this.u_password = u_password; } public Date getU_createDate() { return u_createDate; } public void setU_createDate(Date u_createDate) { this.u_createDate = u_createDate; } public String getU_weiboaccount() { return u_weiboaccount; } public void setU_weiboaccount(String u_weiboaccount) { this.u_weiboaccount = u_weiboaccount; } public String getU_qqaccount() { return u_qqaccount; } public void setU_qqaccount(String u_qqaccount) { this.u_qqaccount = u_qqaccount; } public String getU_weChataccount() { return u_weChataccount; } public void setU_weChataccount(String u_weChataccount) { this.u_weChataccount = u_weChataccount; } public Integer getU_delete() { return u_delete; } public void setU_delete(Integer u_delete) { this.u_delete = u_delete; } public Userinformation getUserInfo() { return userInfo; } public void setUserInfo(Userinformation userInfo) { this.userInfo = userInfo; } public Users(Integer u_id, Integer r_id, String u_mobilephone, String u_password, Date u_createDate, String u_weiboaccount, String u_qqaccount, String u_weChataccount, Integer u_delete, Userinformation userInfo) { super(); this.u_id = u_id; this.r_id = r_id; this.u_mobilephone = u_mobilephone; this.u_password = u_password; this.u_createDate = u_createDate; this.u_weiboaccount = u_weiboaccount; this.u_qqaccount = u_qqaccount; this.u_weChataccount = u_weChataccount; this.u_delete = u_delete; this.userInfo = userInfo; } }
2.新建 mapper的接口 可以看到 前面说的 我的映射文件 和 dao放一个包里面了 名字也一样 方便管理
2.1 先看 UserMapper.java 这个 Mapper 也就是曾经的DAO接口
package com.hover.mapper; import org.apache.ibatis.annotations.Param; public interface UserMapper { /** * 用户登录的方法 * @return */ public Integer userLogin(@Param("userCode")String userCode,@Param("password")String password); }
2.2下面是 UserMapper.xml 这个是Mapper的映射文件 (这边强调一下 所有的命名都是 XXXMapper.xml)因为配置文件扫描的时候 我的规则是*Mapper.xml 你们也可改动 新手的话不要改了 (eg:我也是看着别的博主的博客学习 才会的 也是新手)
代码里面的 <mapper namespace="com.hover.mapper.UserMapper"> 这句话当中的 namespace记得改成你的 这个相当于命名空间是唯一的 规范:包名+*Mapper的名字
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.hover.mapper.UserMapper"> <select id="userLogin" resultType="java.lang.Integer"> SELECT COUNT(1) FROM users WHERE u_mobilePhone=#{userCode} AND u_password=#{password} AND r_id<=3 </select> </mapper>
3.下面来看UserService.java
package com.hover.service; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Service; @Service public interface UserService { /** * 用户登录的方法 * @return */ public Integer userLogin(@Param("userCode")String userCode, @Param("password")String password); }
4.接下来是 UserServiceImpl.java 也就是 Service层的实现 这边 有用到注解
package com.hover.service.impl; import com.hover.mapper.UserMapper; import com.hover.service.UserService; import org.springframework.stereotype.Service; import javax.annotation.Resource; @Service public class UserServiceImpl implements UserService { @Resource private UserMapper userMapper; @Override public Integer userLogin(String userCode,String password) { return userMapper.userLogin(userCode,password); } }
5.下面就是最后一步了 UserController.java 控制层 如果是用Servlet的话 他应该跟Servlet作用差不多吧 我的理解 大佬勿喷 最后那个return "login" 是返回login.jsp 配置文件配置了 视图解析器 所以说不用返回login.jsp 直接 login就行了
package com.hover.controller; import com.hover.service.UserService; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @Controller @RequestMapping("/userController") public class UserController { @Resource private UserService userService; @RequestMapping("userLogin") public String userLogin(@RequestParam("userCode")String userCode, @RequestParam("password")String password, HttpServletRequest request){ Integer result=userService.userLogin(userCode,password); System.out.println("用户的用户名:"+userCode); System.out.println("用户的密码:"+password); if (result>0){ System.out.println("登录成功!"); return "index"; }else{ System.out.println("登录失败!"); request.setAttribute("error","账号或者密码输入错误"); } return "login"; } }
下面来看看 login.jsp的代码
<%-- Created by IntelliJ IDEA. User: Yang Date: 2019/8/25 Time: 21:04 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>登录页面</title> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/css/universalStyle.css"/> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/css/login.css"/> </head> <body> <div id="login_form"> <form action="${pageContext.request.contextPath }/userController/userLogin" method="post"> <div id="login_left"> <img src="${pageContext.request.contextPath }/static/img/login/loginImage.png"/> </div> <div id="login_right"> <p>24小时观察员</p> <div id="login_userName"> <p>账号*</p> <p><input type="text" name="userCode" required placeholder="请输入账号"/></p> </div> <div id="login_password"> <p>密码*</p> <p><input type="password" name="password" required placeholder="请输入密码"/></p> </div> <p><input type="submit" name="login"value="登陆"/></p> <p><img src="${pageContext.request.contextPath }/static/img/login/loginFailedImage.png"/>密码输入错误</p> <p><input type="checkbox" name="rememberPwd"/>记住密码</p> </div> </form> </div> </body> </html>
OK了基本上 就通了 其中好多地方都没说明白 有什么问题在QQ联系:1336486608 这个项目有点其他问题 暂时不能大家共享 有什么问题直接联系我
前面基本上完成了项目搭建 这边 有个Maven的配置 可以看看 使用阿里的仓库下载jar包快 需要改一下 conf-settings.xml 配置文件 切换成 阿里的仓库 你要是FQ 什么的 那默认用国外的也行 具体Maven下载是个什么 自行百度
我那个下载地址在 E:maven 根据自己的 改就行
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- | This is the configuration file for Maven. It can be specified at two levels: | | 1. User Level. This settings.xml file provides configuration for a single user, | and is normally provided in ${user.home}/.m2/settings.xml. | | NOTE: This location can be overridden with the CLI option: | | -s /path/to/user/settings.xml | | 2. Global Level. This settings.xml file provides configuration for all Maven | users on a machine (assuming they're all using the same Maven | installation). It's normally provided in | ${maven.conf}/settings.xml. | | NOTE: This location can be overridden with the CLI option: | | -gs /path/to/global/settings.xml | | The sections in this sample file are intended to give you a running start at | getting the most out of your Maven installation. Where appropriate, the default | values (values used when the setting is not specified) are provided. | |--> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>E:\maven</localRepository> <!-- interactiveMode | This will determine whether maven prompts you when it needs input. If set to false, | maven will use a sensible default value, perhaps based on some other setting, for | the parameter in question. | | Default: true <interactiveMode>true</interactiveMode> --> <!-- offline | Determines whether maven should attempt to connect to the network when executing a build. | This will have an effect on artifact downloads, artifact deployment, and others. | | Default: false <offline>false</offline> --> <!-- pluginGroups | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e. | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list. |--> <pluginGroups> <!-- pluginGroup | Specifies a further group identifier to use for plugin lookup. <pluginGroup>com.your.plugins</pluginGroup> --> </pluginGroups> <!-- proxies | This is a list of proxies which can be used on this machine to connect to the network. | Unless otherwise specified (by system property or command-line switch), the first proxy | specification in this list marked as active will be used. |--> <proxies> <!-- proxy | Specification for one proxy, to be used in connecting to the network. | <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <username>proxyuser</username> <password>proxypass</password> <host>proxy.host.net</host> <port>80</port> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> --> </proxies> <!-- servers | This is a list of authentication profiles, keyed by the server-id used within the system. | Authentication profiles can be used whenever maven must make a connection to a remote server. |--> <servers> <!-- server | Specifies the authentication information to use when connecting to a particular server, identified by | a unique name within the system (referred to by the 'id' attribute below). | | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are | used together. | <server> <id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> </server> --> <!-- Another sample, using keys to authenticate. <server> <id>siteServer</id> <privateKey>/path/to/private/key</privateKey> <passphrase>optional; leave empty if not used.</passphrase> </server> --> </servers> <!-- mirrors | This is a list of mirrors to be used in downloading artifacts from remote repositories. | | It works like this: a POM may declare a repository to use in resolving certain artifacts. | However, this repository may have problems with heavy traffic at times, so people have mirrored | it to several places. | | That repository definition will have a unique id, so we can create a mirror reference for that | repository, to be used as an alternate download site. The mirror site will be the preferred | server for that repository. |--> <mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <!--<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>--> <mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror> <mirror> <id>nexus-163</id> <mirrorOf>*</mirrorOf> <name>Nexus 163</name> <url>http://mirrors.163.com/maven/repository/maven-public/</url> </mirror> <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> </mirrors> <!-- profiles | This is a list of profiles which can be activated in a variety of ways, and which can modify | the build process. Profiles provided in the settings.xml are intended to provide local machine- | specific paths and repository locations which allow the build to work in the local environment. | | For example, if you have an integration testing plugin - like cactus - that needs to know where | your Tomcat instance is installed, you can provide a variable here such that the variable is | dereferenced during the build process to configure the cactus plugin. | | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles | section of this document (settings.xml) - will be discussed later. Another way essentially | relies on the detection of a system property, either matching a particular value for the property, | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'. | Finally, the list of active profiles can be specified directly from the command line. | | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact | repositories, plugin repositories, and free-form properties to be used as configuration | variables for plugins in the POM. | |--> <profiles> <!-- profile | Specifies a set of introductions to the build process, to be activated using one or more of the | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/> | or the command line, profiles have to have an ID that is unique. | | An encouraged best practice for profile identification is to use a consistent naming convention | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc. | This will make it more intuitive to understand what the set of introduced profiles is attempting | to accomplish, particularly when you only have a list of profile id's for debug. | | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo. <profile> <id>jdk-1.4</id> <activation> <jdk>1.4</jdk> </activation> <repositories> <repository> <id>jdk14</id> <name>Repository for JDK 1.4 builds</name> <url>http://www.myhost.com/maven/jdk14</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> --> <!-- | Here is another profile, activated by the system property 'target-env' with a value of 'dev', | which provides a specific path to the Tomcat instance. To use this, your plugin configuration | might hypothetically look like: | | ... | <plugin> | <groupId>org.myco.myplugins</groupId> | <artifactId>myplugin</artifactId> | | <configuration> | <tomcatLocation>${tomcatPath}</tomcatLocation> | </configuration> | </plugin> | ... | | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to | anything, you could just leave off the <value/> inside the activation-property. | <profile> <id>env-dev</id> <activation> <property> <name>target-env</name> <value>dev</value> </property> </activation> <properties> <tomcatPath>/path/to/tomcat/instance</tomcatPath> </properties> </profile> --> </profiles> <!-- activeProfiles | List of profiles that are active for all builds. | <activeProfiles> <activeProfile>alwaysActiveProfile</activeProfile> <activeProfile>anotherAlwaysActiveProfile</activeProfile> </activeProfiles> --> </settings>