首页 > 代码库 > taotao--maven框架搭建思路(用时1下午+1晚上)

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包的版本号。

内容如下:

<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,单元测试,日志处理工具。

<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.

 <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,连接池信息。

<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的配置。

<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里面基本不用配置什么信息。

<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文件

<?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等。

 

taotao--maven框架搭建思路(用时1下午+1晚上)