taotao--maven框架搭建思路(用时1下午+1晚上)
一、确定依赖关系
整个项目分成三个部分:
parent:pom,负责聚合整个项目,确定所有jar包的版本。
common:jar包,放置通用的组件,工具类。
manage:pom,负责聚合后台的web ,service,mapper,pojo.
二、Maven配置
解压maven,并配置到环境变量。可以参考:http://blog.csdn.net/wangmei4968/article/details/50086411
三、根据依赖创建maven项目,并配置xml文件。
parent的pom文件中,放置了所有jar包的版本号。
内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | < 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 > < parent > < groupId >com.taotao</ groupId > < artifactId >taotao-parent</ artifactId > < version >0.0.1-SNAPSHOT</ version > </ parent > < groupId >com.taotao</ groupId > < artifactId >taotao-common</ artifactId > < version >0.0.1-SNAPSHOT</ version > <!-- jar包依赖 --> < dependencies > <!-- 时间操作组件 --> < dependency > < groupId >joda-time</ groupId > < artifactId >joda-time</ artifactId > </ dependency > <!-- Apache工具组件 --> < dependency > < groupId >org.apache.commons</ groupId > < artifactId >commons-lang3</ artifactId > </ dependency > < dependency > < groupId >org.apache.commons</ groupId > < artifactId >commons-io</ artifactId > </ dependency > < dependency > < groupId >commons-net</ groupId > < artifactId >commons-net</ artifactId > </ dependency > <!-- Jackson Json处理工具包 --> < dependency > < groupId >com.fasterxml.jackson.core</ groupId > < artifactId >jackson-databind</ artifactId > </ dependency > <!-- httpclient --> < dependency > < groupId >org.apache.httpcomponents</ groupId > < artifactId >httpclient</ artifactId > </ dependency > <!-- 单元测试 --> < dependency > < groupId >junit</ groupId > < artifactId >junit</ artifactId > < scope >test</ scope > </ dependency > <!-- 日志处理 --> < dependency > < groupId >org.slf4j</ groupId > < artifactId >slf4j-log4j12</ artifactId > </ dependency > </ dependencies > </ project > |
common的pom文件主要放置了时间操作,apache工具,Json处理工具,httpclient,单元测试,日志处理工具。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | < 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 > < parent > < groupId >com.taotao</ groupId > < artifactId >taotao-parent</ artifactId > < version >0.0.1-SNAPSHOT</ version > </ parent > < groupId >com.taotao</ groupId > < artifactId >taotao-common</ artifactId > < version >0.0.1-SNAPSHOT</ version > <!-- jar包依赖 --> < dependencies > <!-- 时间操作组件 --> < dependency > < groupId >joda-time</ groupId > < artifactId >joda-time</ artifactId > </ dependency > <!-- Apache工具组件 --> < dependency > < groupId >org.apache.commons</ groupId > < artifactId >commons-lang3</ artifactId > </ dependency > < dependency > < groupId >org.apache.commons</ groupId > < artifactId >commons-io</ artifactId > </ dependency > < dependency > < groupId >commons-net</ groupId > < artifactId >commons-net</ artifactId > </ dependency > <!-- Jackson Json处理工具包 --> < dependency > < groupId >com.fasterxml.jackson.core</ groupId > < artifactId >jackson-databind</ artifactId > </ dependency > <!-- httpclient --> < dependency > < groupId >org.apache.httpcomponents</ groupId > < artifactId >httpclient</ artifactId > </ dependency > <!-- 单元测试 --> < dependency > < groupId >junit</ groupId > < artifactId >junit</ artifactId > < scope >test</ scope > </ dependency > <!-- 日志处理 --> < dependency > < groupId >org.slf4j</ groupId > < artifactId >slf4j-log4j12</ artifactId > </ dependency > </ dependencies > </ project > |
manager的pom文件,主要进行依赖管理,配置tomcat插件。创建manager的子项时候,创建的是maven model.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | < 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 > < parent > < groupId >com.taotao</ groupId > < artifactId >taotao-parent</ artifactId > < version >0.0.1-SNAPSHOT</ version > </ parent > < groupId >com.taotao</ groupId > < artifactId >taotao-manager</ artifactId > < version >0.0.1-SNAPSHOT</ version > < packaging >pom</ packaging > <!-- 依赖管理 --> < dependencies > < dependency > < groupId >com.taotao</ groupId > < artifactId >taotao-common</ artifactId > < version >0.0.1-SNAPSHOT</ version > </ dependency > </ dependencies > < modules > < module >taotao-manager-pojo</ module > < module >taotao-manager-mapper</ module > < module >taotao-manager-service</ module > < module >taotao-manager-web</ module > </ modules > <!-- 配置插件 --> < build > < plugins > <!-- 配置Tomcat插件 --> < plugin > < groupId >org.apache.tomcat.maven</ groupId > < artifactId >tomcat7-maven-plugin</ artifactId > < configuration > < port >8080</ port > < path >/</ path > </ configuration > </ plugin > </ plugins > </ build > </ project > |
mapper的pom文件,主要防止依赖管理,mysql,连接池信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | < 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 > < parent > < groupId >com.taotao</ groupId > < artifactId >taotao-manager</ artifactId > < version >0.0.1-SNAPSHOT</ version > </ parent > < artifactId >taotao-manager-mapper</ artifactId > <!-- 依赖管理 --> < dependencies > < dependency > < groupId >com.taotao</ groupId > < artifactId >taotao-manager-pojo</ artifactId > < version >0.0.1-SNAPSHOT</ version > </ dependency > <!-- Mybatis --> < dependency > < groupId >org.mybatis</ groupId > < artifactId >mybatis</ artifactId > < version >${mybatis.version}</ version > </ dependency > < dependency > < groupId >org.mybatis</ groupId > < artifactId >mybatis-spring</ artifactId > < version >${mybatis.spring.version}</ version > </ dependency > < dependency > < groupId >com.github.miemiedev</ groupId > < artifactId >mybatis-paginator</ artifactId > < version >${mybatis.paginator.version}</ version > </ dependency > < dependency > < groupId >com.github.pagehelper</ groupId > < artifactId >pagehelper</ artifactId > < version >${pagehelper.version}</ version > </ dependency > <!-- MySql --> < dependency > < groupId >mysql</ groupId > < artifactId >mysql-connector-java</ artifactId > < version >${mysql.version}</ version > </ dependency > <!-- 连接池 --> < dependency > < groupId >com.alibaba</ groupId > < artifactId >druid</ artifactId > < version >${druid.version}</ version > </ dependency > </ dependencies > </ project > |
servcie的pom里面,主要配置依赖管理,还有一些spring的配置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | < 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 > < parent > < groupId >com.taotao</ groupId > < artifactId >taotao-manager</ artifactId > < version >0.0.1-SNAPSHOT</ version > </ parent > < artifactId >taotao-manager-service</ artifactId > <!-- 依赖管理 --> < dependencies > < dependency > < groupId >com.taotao</ groupId > < artifactId >taotao-manager-mapper</ artifactId > < version >0.0.1-SNAPSHOT</ version > </ dependency > <!-- Spring --> < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-context</ artifactId > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-beans</ artifactId > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-webmvc</ artifactId > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-jdbc</ artifactId > </ dependency > < dependency > < groupId >org.springframework</ groupId > < artifactId >spring-aspects</ artifactId > </ dependency > </ dependencies > </ project > |
pojo里面基本不用配置什么信息。
1 2 3 4 5 6 7 8 9 | < 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 > < parent > < groupId >com.taotao</ groupId > < artifactId >taotao-manager</ artifactId > < version >0.0.1-SNAPSHOT</ version > </ parent > < artifactId >taotao-manager-pojo</ artifactId > </ project > |
四、配置完成后,进行maven的clean,install,如果中间代码当不下来,可以查看.m2里面的settings.xml文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | <? xml version="1.0" encoding="UTF-8" standalone="no"?> < 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 >D:\taotaoproject\repository</ localRepository > <!-- 设置发布 jar 包时的用户名及密 --> < servers > < server > < id >releases</ id > < username >admin</ username > < password >admin123</ password > </ server > < server > < id >snapshots</ id > < username >admin</ username > < password >admin123</ password > </ server > </ servers > <!-- 设置 maven 的远程仓库为 nexus --> < mirrors > < mirror > < id >nexus</ id > < mirrorOf >central</ mirrorOf > < name >nexus repository</ name > < url >http://192.168.22.246:8081/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> --> </ mirrors > <!-- 设置 central 的路径等 --> < profiles > < profile > < id >central</ id > < repositories > < repository > < id >central</ id > < name >Central</ name > < url >http://192.168.22.246:8081/nexus/content/groups/public</ url > </ repository > </ repositories > < pluginRepositories > < pluginRepository > < id >central</ id > < name >Central</ name > < url >http://192.168.22.246:8081/nexus/content/groups/public</ url > </ pluginRepository > </ pluginRepositories > </ profile > </ profiles > < activeProfiles > < activeProfile >central</ activeProfile > </ activeProfiles > <!-- 配置eclipse插件 --> < pluginGroups > < pluginGroup >org.mortbay.jetty</ pluginGroup > < pluginGroup >org.codehaus.cargo</ pluginGroup > < pluginGroup >org.jvnet.hudson.tools</ pluginGroup > </ pluginGroups > </ settings > |
http://192.168.22.246:8081/nexus/content/groups/public 为私服的地址,可以进去查看是否有该jar包,该jar包版本是否正确。
maven常用命令:
maven clean ,清除产生的项目
maven install,编译
maven test,运行测试
maven generate-sources.产生应用需要的任何额外的源代码
此处通过install下载jar包,最后选择Maven build, 输入clean tomcat7:run ,进行自带tomcat插件启动。
五、svn管理
安装svn客户端,目录有三:
branches:分支,5.0结项,有bug,6.0正在进行,需要检出分支,进行修改。
tags:存档目录(不允许修改)。
trunk:主干,一般开发代码。
上传代码的时候,右键项目,选择team——share project——创建资源库(从svn复制的url路径)——进行svn关联。
在Team Synchronizing视图里面,要ingnore *.project,*.settings.xml,*.classPath,*.target文件,提交pom ,src,src/site文件。
此文件只需要提交common,manager,parent即可,因为已经在manager里面配置好了关系,所以可以直接提交manager,svn就有了其他文件。但是如果要编辑模块,还要添加maven exist model,例如web ,mapper等。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性