在配置pom.xml 时要注意 <plugin>
里面的配置信息要写一致。
当配置完出错时 要右击工程如图所示更新一下
创建一个maven工程(普通的),名字为springmybatis 是技术架构模块 主要是提供springmvc+mybatis所需的jar包,将所需的jar包导入然后在工程根目录找到pom.xml 文件配置springmvc3.1.4和mybatis3.2.3的依赖
pom.xml文件;如下(此文件中已经配置过父节点即聚合工程模块)
注意(<packaging>jar</packaging>
)
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>
<!--父模块的相对路径 父模块中要有pom.xml -->
<relativePath>../yycgparent</relativePath>
<groupId>yycg</groupId>
<artifactId>yycgparent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<!-- <groupId>yycg</groupId> -->
<artifactId>springmybatis</artifactId>
<!-- <version>0.0.1-SNAPSHOT</version> -->
<packaging>jar</packaging>
<name>springmybatis</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.1.4.RELEASE</spring.version>
<mybatis.version>3.2.3</mybatis.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- springmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId> org.aspectj</groupId>
<artifactId> aspectjweaver</artifactId>
<version> 1.6.11</version>
</dependency>
<!-- mybatis依赖 -->
<dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>2.6.9</version>
<!-- <scope>provided</scope> -->
<!-- <optional>true</optional> -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
<!-- <optional>true</optional> -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<!-- <optional>true</optional> -->
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<!-- <optional>true</optional> -->
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-beta9</version>
<!-- <optional>true</optional> -->
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<!-- <optional>true</optional> -->
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.17.1-GA</version>
<!-- <optional>true</optional> -->
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
<!-- <optional>true</optional> -->
</dependency>
<!-- spring mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-infrastructure</artifactId>
<version>2.2.2.RELEASE</version>
<!-- <scope>provided</scope> -->
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-jdbc</artifactId>
<version>3.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.10.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<!-- <scope>test</scope> -->
</dependency>
</dependencies>
<build>
<finalName>springmybatis</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
创建一个maven工程(java工程),yycgutil
先将所需的工具类拷贝到src/main/java中。
在pom.xml添加依赖。
pom.xml文件如下(此文件中已经配置过父节点即聚合工程模块)
注意(<packaging>jar</packaging>
)
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>
<!--父模块的相对路径 父模块中要有pom.xml -->
<relativePath>../yycgparent</relativePath>
<groupId>yycg</groupId>
<artifactId>yycgparent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<!-- <groupId>yycg</groupId> -->
<artifactId>yycgutil</artifactId>
<!-- <version>0.0.1-SNAPSHOT</version> -->
<packaging>jar</packaging>
<name>yycgutil</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- 汉字拼音组件 -->
<dependency>
<groupId>net.sourceforge</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
<!-- office文档组件 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
</dependency>
<!-- json转换 -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.11</version>
</dependency>
<!-- 加解密 -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
<version>1.46</version>
</dependency>
<!-- java servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>yycgutil</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
创建一个maven工程(maven-archetype-webapp),包括:base(业务基础模块)和business(业务模块)。
同样配置pom.xml(将工具模块和技术架构模块都添加进去)
注意(<packaging>war</packaging>
)
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<!--父模块的相对路径 父模块中要有pom.xml -->
<relativePath>../yycgparent</relativePath>
<groupId>yycg</groupId>
<artifactId>yycgparent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<!-- <groupId>yycg</groupId> -->
<artifactId>yycgproject</artifactId>
<packaging>war</packaging>
<!-- <version>0.0.1-SNAPSHOT</version> -->
<name>yycgproject</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- 添加技術依賴架構模塊 -->
<dependency>
<groupId>yycg</groupId>
<artifactId>springmybatis</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- 添加工具模塊 -->
<dependency>
<groupId>yycg</groupId>
<artifactId>yycgutil</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- dbcp -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<!-- ojdbc14 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.1.0</version>
<scope>runtime</scope>
</dependency>
<!-- servlet-api 编译时用,发布后不用 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- jstl标签 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- 文件上传 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
<!-- commons io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- json转换 ,springmvc 返回json格式必须加入-->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.11</version>
</dependency>
<!-- dwr -->
<dependency>
<groupId>org.directwebremoting</groupId>
<artifactId>dwr</artifactId>
<version>3.0.M1</version>
</dependency>
</dependencies>
<build>
<finalName>yycgproject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- war包生成插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
</configuration>
</plugin>
<!-- tomcat运行插件 -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<home>D:\java\tomcat</home>
</container>
<configuration>
<type>existing</type>
<home>D:\java\tomcat</home>
</configuration>
</configuration>
<executions>
<execution>
<id>cargo-run</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
该模块是为了便于测试人员测试
开发在eclipse上开发,将开发后的代码提交svn。
测试从svn上得到代码,编译,打成war包,将war拷贝到测试服务器。
测试人员将各各模块从svn上得下,只需要在聚合工程目录 中,运行maven命令,将各各工程聚合,生成war包。
聚合工程:yycgparent
负责:将各各工程模块聚合不需要开发。
需要在各各子工程模块,添加父模结点,让子模块继承父模块(上面已写)
需要自动生成 war包,需要在yycgproject的pom.xml添加生成war的插件。(已添加)
pom.xml 文件配置好了以后
在cmd命令行执行工程聚合,达到一步构建。
cmd进入yycgparent,
在cmd下运行mvn install。
Cmd运行mvn命令,先找用户setting.xml(建议删除了),再去找maven安装目录 中的conf下的setting.xml(全局配置,一定要配置本地仓库)。
运行mvn install之后 ,检查本地仓库,是否三个工程jar发布到本地仓库。
创建maven工程,修改pom.xml文件:
<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>yycg</groupId>
<artifactId>yycgparent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<!-- 设定子模块的目录,目录要有pom.xml,使用相对路径 -->
<module>../yycgproject</module>
<module>../yycgutil</module>
<module>../springmybatis</module>
</modules>
<name>yycgparent</name>
<url>http://maven.apache.org</url>
</project>